Move config.h before other includes (which may use feature tests).
[emacs.git] / lisp / ps-print.el
blob6ca81f7eb72a7fed776f313d4a1ef6bde49cf0c1
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/06/21 14:10:51 vinicius>
13 ;; Version: 5.2.3
15 (defconst ps-print-version "5.2.3"
16 "ps-print.el, v 5.2.3 <2000/06/21 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)
31 ;; any later version.
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.
43 ;;; Commentary:
45 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
47 ;; About ps-print
48 ;; --------------
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).
65 ;; Using ps-print
66 ;; --------------
68 ;; ps-print provides eight commands for generating PostScript images
69 ;; of Emacs buffers:
71 ;; ps-print-buffer
72 ;; ps-print-buffer-with-faces
73 ;; ps-print-region
74 ;; ps-print-region-with-faces
75 ;; ps-spool-buffer
76 ;; ps-spool-buffer-with-faces
77 ;; ps-spool-region
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
89 ;; printer;
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
129 ;; printer.
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.
138 ;; Invoking Ps-Print
139 ;; -----------------
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
191 ;; `printer-name'.
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 ;; The variable `ps-manual-feed' indicates if the printer will manually feed
199 ;; paper. If it's nil, automatic feeding takes place. If it's non-nil, manual
200 ;; feeding takes place. The default is nil (automatic feeding).
202 ;; If you're using Emacs for Windows 95/98/NT or MS-DOS, don't forget to
203 ;; customize the following variables: `ps-printer-name', `ps-lpr-command',
204 ;; `ps-lpr-switches' and `ps-spool-config'. See these variables documentation
205 ;; in the code or by typing, for example, C-h v ps-printer-name RET.
208 ;; The Page Layout
209 ;; ---------------
211 ;; All dimensions are floats in PostScript points.
212 ;; 1 inch == 2.54 cm == 72 points
213 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
215 ;; The variable `ps-paper-type' determines the size of paper ps-print formats
216 ;; for; it should contain one of the symbols: `a4' `a3' `letter' `legal'
217 ;; `letter-small' `tabloid' `ledger' `statement' `executive' `a4small' `b4'
218 ;; `b5'.
220 ;; If variable `ps-warn-paper-type' is nil, it's *not* given an error if
221 ;; PostScript printer doesn't have a paper with the size indicated by
222 ;; `ps-paper-type', instead it uses the default paper size. If variable
223 ;; `ps-warn-paper-type' is non-nil, it's given an error if PostScript printer
224 ;; doesn't have a paper with the size indicated by `ps-paper-type'. It's used
225 ;; when `ps-spool-config' is set to `setpagedevice' (see section Duplex
226 ;; Printers). The default value is non-nil (it gives an error).
228 ;; The variable `ps-landscape-mode' determines the orientation of the printing
229 ;; on the page: nil means `portrait' mode, non-nil means `landscape' mode.
230 ;; There is no oblique mode yet, though this is easy to do in ps.
232 ;; In landscape mode, the text is NOT scaled: you may print 70 lines in portrait
233 ;; mode and only 50 lines in landscape mode. The margins represent margins in
234 ;; the printed paper: the top margin is the margin between the top of the page
235 ;; and the printed header, whatever the orientation is.
237 ;; The variable `ps-number-of-columns' determines the number of columns both in
238 ;; landscape and portrait mode.
239 ;; You can use:
240 ;; - (the standard) one column portrait mode.
241 ;; - (my favorite) two columns landscape mode (which spares trees).
242 ;; but also:
243 ;; - one column landscape mode for files with very long lines.
244 ;; - multi-column portrait or landscape mode.
246 ;; The variable `ps-print-upside-down' determines other orientation for printing
247 ;; page: nil means `normal' printing, non-nil means `upside-down' printing. The
248 ;; default value is nil (`normal' printing).
250 ;; The `upside-down' orientation can be used in portrait or landscape mode.
252 ;; The variable `ps-selected-pages' specifies which pages to print. If it's
253 ;; nil, all pages are printed. If it's a list, the list element may be an
254 ;; integer or a cons cell (FROM . TO) designating FROM page to TO page; any
255 ;; invalid element is ignored, that is, an integer lesser than one or if FROM
256 ;; is greater than TO. Otherwise, it's treated as nil. The default value is
257 ;; nil (print all pages). After ps-print processing `ps-selected-pages' is set
258 ;; to nil. But the latest `ps-selected-pages' is saved in
259 ;; `ps-last-selected-pages' (see it for documentation). So you can restore the
260 ;; latest selected pages by using `ps-last-selected-pages' or by calling
261 ;; `ps-restore-selected-pages' command (see it for documentation).
264 ;; Horizontal layout
265 ;; -----------------
267 ;; The horizontal layout is determined by the variables
268 ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
269 ;; as follows:
271 ;; ------------------------------------------
272 ;; | | | | | | | |
273 ;; | lm | text | ic | text | ic | text | rm |
274 ;; | | | | | | | |
275 ;; ------------------------------------------
277 ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
278 ;; Usually, lm = rm > 0 and ic = lm
279 ;; If (ic < 0), the text of adjacent columns can overlap.
282 ;; Vertical layout
283 ;; ---------------
285 ;; The vertical layout is determined by the variables
286 ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
287 ;; as follows:
289 ;; |--------| |--------|
290 ;; | tm | | tm |
291 ;; |--------| |--------|
292 ;; | header | | |
293 ;; |--------| | |
294 ;; | ho | | |
295 ;; |--------| or | text |
296 ;; | | | |
297 ;; | text | | |
298 ;; | | | |
299 ;; |--------| |--------|
300 ;; | bm | | bm |
301 ;; |--------| |--------|
303 ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
304 ;; The margins represent margins in the printed paper:
305 ;; the top margin is the margin between the top of the page
306 ;; and the printed header, whatever the orientation is.
309 ;; Headers
310 ;; -------
312 ;; ps-print can print headers at the top of each column or at the top
313 ;; of each page; the default headers contain the following four items:
314 ;; on the left, the name of the buffer and, if the buffer is visiting
315 ;; a file, the file's directory; on the right, the page number and
316 ;; date of printing. The default headers look something like this:
318 ;; ps-print.el 1/21
319 ;; /home/jct/emacs-lisp/ps/new 94/12/31
321 ;; When printing on duplex printers, left and right are reversed so
322 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
324 ;; Headers are configurable:
325 ;; To turn them off completely, set `ps-print-header' to nil.
326 ;; To turn off the header's gaudy framing box,
327 ;; set `ps-print-header-frame' to nil.
329 ;; To print only one header at the top of each page,
330 ;; set `ps-print-only-one-header' to t.
332 ;; To switch headers, set `ps-switch-header' to:
334 ;; nil Never switch headers.
336 ;; t Always switch headers.
338 ;; duplex Switch headers only when duplexing is on, that is, when
339 ;; `ps-spool-duplex' is non-nil (see Duplex Printers).
341 ;; Any other value is treated as t. The default value is `duplex'.
343 ;; The font family and size of text in the header are determined
344 ;; by the variables `ps-header-font-family', `ps-header-font-size' and
345 ;; `ps-header-title-font-size' (see below).
347 ;; The variable `ps-header-line-pad' determines the portion of a header
348 ;; title line height to insert between the header frame and the text
349 ;; it contains, both in the vertical and horizontal directions:
350 ;; .5 means half a line.
352 ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
353 ;; to omit the total page count and just print the page number,
354 ;; set `ps-show-n-of-n' to nil.
356 ;; The amount of information in the header can be changed by changing
357 ;; the number of lines. To show less, set `ps-header-lines' to 1, and
358 ;; the header will show only the buffer name and page number. To show
359 ;; more, set `ps-header-lines' to 3, and the header will show the time of
360 ;; printing below the date.
362 ;; To change the content of the headers, change the variables
363 ;; `ps-left-header' and `ps-right-header'.
364 ;; These variables are lists, specifying top-to-bottom the text
365 ;; to display on the left or right side of the header.
366 ;; Each element of the list should be a string or a symbol.
367 ;; Strings are inserted directly into the PostScript arrays,
368 ;; and should contain the PostScript string delimiters '(' and ')'.
370 ;; Symbols in the header format lists can either represent functions
371 ;; or variables. Functions are called, and should return a string to
372 ;; show in the header. Variables should contain strings to display in
373 ;; the header. In either case, function or variable, the PostScript
374 ;; string delimiters are added by ps-print, and should not be part of
375 ;; the returned value.
377 ;; Here's an example: say we want the left header to display the text
379 ;; Moe
380 ;; Larry
381 ;; Curly
383 ;; where we have a function to return "Moe"
385 ;; (defun moe-func ()
386 ;; "Moe")
388 ;; a variable specifying "Larry"
390 ;; (setq larry-var "Larry")
392 ;; and a literal for "Curly". Here's how `ps-left-header' should be
393 ;; set:
395 ;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
397 ;; Note that Curly has the PostScript string delimiters inside his
398 ;; quotes -- those aren't misplaced lisp delimiters!
400 ;; Without them, PostScript would attempt to call the undefined
401 ;; function Curly, which would result in a PostScript error.
403 ;; Since most printers don't report PostScript errors except by
404 ;; aborting the print job, this kind of error can be hard to track down.
406 ;; Consider yourself warned!
409 ;; PostScript Prologue Header
410 ;; --------------------------
412 ;; It is possible to add PostScript prologue header comments besides that
413 ;; ps-print generates by setting the variable `ps-print-prologue-header'.
415 ;; `ps-print-prologue-header' may be a string or a symbol function which returns
416 ;; a string. Note that this string is inserted on PostScript prologue header
417 ;; section which is used to define some document characteristic through
418 ;; PostScript special comments, like "%%Requirements: jog\n".
420 ;; By default `ps-print-prologue-header' is nil.
422 ;; ps-print always inserts the %%Requirements: comment, so if you need to insert
423 ;; more requirements put them first in `ps-print-prologue-header' using the
424 ;; "%%+" comment. For example, if you need to set numcopies to 3 and jog on
425 ;; requirements and set %%LanguageLevel: to 2, do:
427 ;; (setq ps-print-prologue-header
428 ;; "%%+ numcopies(3) jog\n%%LanguageLevel: 2\n")
430 ;; The duplex requirement is inserted by ps-print (see section Duplex Printers).
432 ;; Do not forget to terminate the string with "\n".
434 ;; For more information about PostScript document comments, see:
435 ;; PostScript Language Reference Manual (2nd edition)
436 ;; Adobe Systems Incorporated
437 ;; Appendix G: Document Structuring Conventions -- Version 3.0
439 ;; It is also possible to add an user defined PostScript prologue code before
440 ;; all generated prologue code by setting the variable
441 ;; `ps-user-defined-prologue'.
443 ;; `ps-user-defined-prologue' may be a string or a symbol function which returns
444 ;; a string. Note that this string is inserted after `ps-adobe-tag' and
445 ;; PostScript prologue comments, and before ps-print PostScript prologue code
446 ;; section. That is, this string is inserted after error handler initialization
447 ;; and before ps-print settings.
449 ;; By default `ps-user-defined-prologue' is nil.
451 ;; It's recommended to initiate and terminate the string with "\n".
453 ;; It's strongly recommended only insert PostScript code and/or comments
454 ;; specific for your printing system particularities. For example, some special
455 ;; initialization that only your printing system needs.
457 ;; Do not insert code for duplex printing, n-up printing or error handler,
458 ;; ps-print handles this in a suitable way.
460 ;; For more information about PostScript, see:
461 ;; PostScript Language Reference Manual (2nd edition)
462 ;; Adobe Systems Incorporated
465 ;; PostScript Error Handler
466 ;; ------------------------
468 ;; ps-print instruments generated PostScript code with an error handler.
470 ;; The variable `ps-error-handler-message' specifies where the error handler
471 ;; message should be sent.
473 ;; Valid values are:
475 ;; none catch the error and *DON'T* send any message.
477 ;; paper catch the error and print on paper the error message.
478 ;; This is the default value.
480 ;; system catch the error and send back the error message to
481 ;; printing system. This is useful only if printing system
482 ;; send back an email reporting the error, or if there is
483 ;; some other alternative way to report back the error from
484 ;; the system to you.
486 ;; paper-and-system catch the error, print on paper the error message and
487 ;; send back the error message to printing system.
489 ;; Any other value is treated as `paper'.
492 ;; Duplex Printers
493 ;; ---------------
495 ;; If you have a duplex-capable printer (one that prints both sides of the
496 ;; paper), set `ps-spool-duplex' to t.
497 ;; ps-print will insert blank pages to make sure each buffer starts on the
498 ;; correct side of the paper.
500 ;; The variable `ps-spool-config' specifies who is the responsable for setting
501 ;; duplex and page size switches. Valid values are:
503 ;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
504 ;; Don't forget to set `ps-lpr-switches' to select duplex
505 ;; printing for your printer.
507 ;; setpagedevice duplex and page size are configured by ps-print using the
508 ;; setpagedevice PostScript operator.
510 ;; nil duplex and page size are configured by ps-print *not* using
511 ;; the setpagedevice PostScript operator.
513 ;; Any other value is treated as nil.
515 ;; The default value is `lpr-switches'.
517 ;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
518 ;; viewing file generated using landscape. Also on some printers,
519 ;; setpagedevice affects zebra stripes; on other printers,
520 ;; setpagedevice affects the left margin.
521 ;; Besides all that, if your printer does not have the paper size
522 ;; specified by setpagedevice, your printing will be aborted.
523 ;; So, if you need to use setpagedevice, set `ps-spool-config' to
524 ;; `setpagedevice', generate a test file and send it to your printer;
525 ;; if the printed file isn't ok, set `ps-spool-config' to nil.
527 ;; The variable `ps-spool-tumble' specifies how the page images on opposite
528 ;; sides of a sheet are oriented with respect to each other. If
529 ;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
530 ;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
531 ;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
532 ;; The default value is nil.
534 ;; Some printer system prints a header page and forces the first page be printed
535 ;; on header page back, when using duplex. If your printer system has this
536 ;; behavior, set variable `ps-banner-page-when-duplexing' to t.
538 ;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
539 ;; skipped. It's like the very first character of buffer (or region) is ^L
540 ;; (\014).
542 ;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
543 ;; first page).
546 ;; N-up Printing
547 ;; -------------
549 ;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
550 ;; paper. The value specified must be between 1 and 100. The default is 1.
552 ;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
553 ;; to a high value (for example, 23). If this happens, set a lower value.
555 ;; The variable `ps-n-up-margin' specifies the margin in points between the
556 ;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
557 ;; or 28.35 points).
559 ;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
560 ;; The default is t.
562 ;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
563 ;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
564 ;; filling example using a 3x4 page matrix:
566 ;; left-top 1 2 3 4 left-bottom 9 10 11 12
567 ;; 5 6 7 8 5 6 7 8
568 ;; 9 10 11 12 1 2 3 4
570 ;; right-top 4 3 2 1 right-bottom 12 11 10 9
571 ;; 8 7 6 5 8 7 6 5
572 ;; 12 11 10 9 4 3 2 1
574 ;; top-left 1 4 7 10 bottom-left 3 6 9 12
575 ;; 2 5 8 11 2 5 8 11
576 ;; 3 6 9 12 1 4 7 10
578 ;; top-right 10 7 4 1 bottom-right 12 9 6 3
579 ;; 11 8 5 2 11 8 5 2
580 ;; 12 9 6 3 10 7 4 1
582 ;; Any other value is treated as left-top.
584 ;; The default value is left-top.
587 ;; Control And 8-bit Characters
588 ;; ----------------------------
590 ;; The variable `ps-print-control-characters' specifies whether you want to see
591 ;; a printable form for control and 8-bit characters, that is, instead of
592 ;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
594 ;; Valid values for `ps-print-control-characters' are:
596 ;; 8-bit This is the value to use when you want an ASCII encoding of
597 ;; any control or non-ASCII character. Control characters are
598 ;; encoded as "^D", and non-ASCII characters have an
599 ;; octal encoding.
601 ;; control-8-bit This is the value to use when you want an ASCII encoding of
602 ;; any control character, whether it is 7 or 8-bit.
603 ;; European 8-bits accented characters are printed according
604 ;; the current font.
606 ;; control Only ASCII control characters have an ASCII encoding.
607 ;; European 8-bits accented characters are printed according
608 ;; the current font.
610 ;; nil No ASCII encoding. Any character is printed according the
611 ;; current font.
613 ;; Any other value is treated as nil.
615 ;; The default is `control-8-bit'.
617 ;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
620 ;; Printing Multi-byte Buffer
621 ;; --------------------------
623 ;; See ps-mule.el for documentation.
626 ;; Line Number
627 ;; -----------
629 ;; The variable `ps-line-number' specifies whether to number each line;
630 ;; non-nil means do so. The default is nil (don't number each line).
632 ;; The variable `ps-line-number-step' specifies the interval that line number is
633 ;; printed. For example, if `ps-line-number-step' is set to 2, the printing
634 ;; will look like:
636 ;; 1 one line
637 ;; one line
638 ;; 3 one line
639 ;; one line
640 ;; 5 one line
641 ;; one line
642 ;; ...
644 ;; Valid values are:
646 ;; integer an integer that specifies the interval that line number is
647 ;; printed. If it's lesser than or equal to zero, it's used the
648 ;; value 1.
650 ;; `zebra' specifies that only the line number of the first line in a zebra
651 ;; stripe is to be printed.
653 ;; Any other value is treated as `zebra'.
654 ;; The default value is 1, so each line number is printed.
656 ;; The variable `ps-line-number-start' specifies the starting point in the
657 ;; interval given by `ps-line-number-step'. For example, if
658 ;; `ps-line-number-step' is set to 3 and `ps-line-number-start' is set to 3, the
659 ;; printing will look like:
661 ;; one line
662 ;; one line
663 ;; 3 one line
664 ;; one line
665 ;; one line
666 ;; 6 one line
667 ;; one line
668 ;; one line
669 ;; 9 one line
670 ;; one line
671 ;; ...
673 ;; The values for `ps-line-number-start':
675 ;; * If `ps-line-number-step' is an integer, must be between 1 and the value
676 ;; of `ps-line-number-step' inclusive.
678 ;; * If `ps-line-number-step' is set to `zebra', must be between 1 and the
679 ;; value of `ps-zebra-strip-height' inclusive.
681 ;; The default value is 1, so the line number of the first line of each interval
682 ;; is printed.
685 ;; Zebra Stripes
686 ;; -------------
688 ;; Zebra stripes are a kind of background that appear "underneath" the text
689 ;; and can make the text easier to read. They look like this:
691 ;; XXXXXXXXXXXXXXXXXXXXXXXX
692 ;; XXXXXXXXXXXXXXXXXXXXXXXX
693 ;; XXXXXXXXXXXXXXXXXXXXXXXX
697 ;; XXXXXXXXXXXXXXXXXXXXXXXX
698 ;; XXXXXXXXXXXXXXXXXXXXXXXX
699 ;; XXXXXXXXXXXXXXXXXXXXXXXX
701 ;; The blocks of X's represent rectangles filled with a light gray color.
702 ;; Each rectangle extends all the way across the page.
704 ;; The height, in lines, of each rectangle is controlled by
705 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
706 ;; The distance between stripes equals the height of a stripe.
708 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
709 ;; Non-nil means yes, nil means no. The default is nil.
711 ;; The variable `ps-zebra-color' controls the zebra stripes gray scale or RGB
712 ;; color. It should be a float number between 0.0 (black color) and 1.0 (white
713 ;; color), a string which is a color name, or a list of 3 numbers which
714 ;; corresponds to the Red Green Blue color scale.
715 ;; The default is 0.95 (or "gray95", or '(0.95 0.95 0.95)).
717 ;; The variable `ps-zebra-stripe-follow' specifies if zebra stripe should
718 ;; continue on next page or restart on each page. If `ps-zebra-stripe-follow'
719 ;; is nil, zebra stripe is restarted on each page. If `ps-zebra-stripe-follow'
720 ;; is non-nil, zebra stripe continues on next page. Visually, we have:
722 ;; `ps-zebra-stripe-follow' `ps-zebra-stripe-follow'
723 ;; is nil is non-nil
724 ;; Current Page ------------------------ ------------------------
725 ;; 1 XXXXXXXXXXXXXXXXXXXXX 1 XXXXXXXXXXXXXXXXXXXXX
726 ;; 2 XXXXXXXXXXXXXXXXXXXXX 2 XXXXXXXXXXXXXXXXXXXXX
727 ;; 3 XXXXXXXXXXXXXXXXXXXXX 3 XXXXXXXXXXXXXXXXXXXXX
728 ;; 4 4
729 ;; 5 5
730 ;; 6 6
731 ;; 7 XXXXXXXXXXXXXXXXXXXXX 7 XXXXXXXXXXXXXXXXXXXXX
732 ;; 8 XXXXXXXXXXXXXXXXXXXXX 8 XXXXXXXXXXXXXXXXXXXXX
733 ;; ------------------------ ------------------------
734 ;; Next Page ------------------------ ------------------------
735 ;; 9 XXXXXXXXXXXXXXXXXXXXX 9 XXXXXXXXXXXXXXXXXXXXX
736 ;; 10 XXXXXXXXXXXXXXXXXXXXX 10
737 ;; 11 XXXXXXXXXXXXXXXXXXXXX 11
738 ;; 12 12
739 ;; 13 13 XXXXXXXXXXXXXXXXXXXXX
740 ;; 14 14 XXXXXXXXXXXXXXXXXXXXX
741 ;; 15 XXXXXXXXXXXXXXXXXXXXX 15 XXXXXXXXXXXXXXXXXXXXX
742 ;; 16 XXXXXXXXXXXXXXXXXXXXX 16
743 ;; ------------------------ ------------------------
745 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
748 ;; Hooks
749 ;; -----
751 ;; ps-print has the following hook variables:
753 ;; `ps-print-hook'
754 ;; It is evaluated once before any printing process. This is the right
755 ;; place to initialize ps-print global data.
756 ;; For an example, see section Adding a New Font Family.
758 ;; `ps-print-begin-sheet-hook'
759 ;; It is evaluated on each beginning of sheet of paper.
760 ;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
761 ;; evaluated.
763 ;; `ps-print-begin-page-hook'
764 ;; It is evaluated on each beginning of page, except in the beginning
765 ;; of page that `ps-print-begin-sheet-hook' is evaluated.
767 ;; `ps-print-begin-column-hook'
768 ;; It is evaluated on each beginning of column, except in the beginning
769 ;; of column that `ps-print-begin-page-hook' is evaluated or that
770 ;; `ps-print-begin-sheet-hook' is evaluated.
773 ;; Font Managing
774 ;; -------------
776 ;; ps-print now knows rather precisely some fonts: the variable
777 ;; `ps-font-info-database' contains information for a list of font families
778 ;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
779 ;; `NewCenturySchlbk'). Each font family contains the font names for standard,
780 ;; bold, italic and bold-italic characters, a reference size (usually 10) and
781 ;; the corresponding line height, width of a space and average character width.
783 ;; The variable `ps-font-family' determines which font family is to be used for
784 ;; ordinary text. If its value does not correspond to a known font family, an
785 ;; error message is printed into the `*Messages*' buffer, which lists the
786 ;; currently available font families.
788 ;; The variable `ps-font-size' determines the size (in points) of the font for
789 ;; ordinary text, when generating PostScript. Its value is a float or a cons of
790 ;; floats which has the following form:
792 ;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
794 ;; Similarly, the variable `ps-header-font-family' determines which font family
795 ;; is to be used for text in the header.
797 ;; The variable `ps-header-font-size' determines the font size, in points, for
798 ;; text in the header (similar to `ps-font-size').
800 ;; The variable `ps-header-title-font-size' determines the font size, in points,
801 ;; for the top line of text in the header (similar to `ps-font-size').
804 ;; Adding a New Font Family
805 ;; ------------------------
807 ;; To use a new font family, you MUST first teach ps-print
808 ;; this font, i.e., add its information to `ps-font-info-database',
809 ;; otherwise ps-print cannot correctly place line and page breaks.
811 ;; For example, assuming `Helvetica' is unknown,
812 ;; you first need to do the following ONLY ONCE:
814 ;; - create a new buffer
815 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
816 ;; - open this file and find the line:
817 ;; `% 3 cm 20 cm moveto 10/Courier ReportFontInfo showpage'
818 ;; - delete the leading `%' (which is the PostScript comment character)
819 ;; - replace in this line `Courier' by the new font (say `Helvetica')
820 ;; to get the line:
821 ;; `3 cm 20 cm moveto 10/Helvetica ReportFontInfo showpage'
822 ;; - send this file to the printer (or to ghostscript).
823 ;; You should read the following on the output page:
825 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
826 ;; and a crude estimate of average character width is 5.09243
828 ;; - Add these values to the `ps-font-info-database':
829 ;; (setq ps-font-info-database
830 ;; (append
831 ;; '((Helvetica ; the family key
832 ;; (fonts (normal . "Helvetica")
833 ;; (bold . "Helvetica-Bold")
834 ;; (italic . "Helvetica-Oblique")
835 ;; (bold-italic . "Helvetica-BoldOblique"))
836 ;; (size . 10.0)
837 ;; (line-height . 11.56)
838 ;; (space-width . 2.78)
839 ;; (avg-char-width . 5.09243)))
840 ;; ps-font-info-database))
841 ;; - Now you can use this font family with any size:
842 ;; (setq ps-font-family 'Helvetica)
843 ;; - if you want to use this family in another emacs session, you must
844 ;; put into your `~/.emacs':
845 ;; (require 'ps-print)
846 ;; (setq ps-font-info-database (append ...)))
847 ;; if you don't want to load ps-print, you have to copy the whole value:
848 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
849 ;; or, use `ps-print-hook' (see section Hooks):
850 ;; (add-hook 'ps-print-hook
851 ;; '(lambda ()
852 ;; (or (assq 'Helvetica ps-font-info-database)
853 ;; (setq ps-font-info-database (append ...)))))
855 ;; You can create new `mixed' font families like:
856 ;; (my-mixed-family
857 ;; (fonts (normal . "Courier-Bold")
858 ;; (bold . "Helvetica")
859 ;; (italic . "Zapf-Chancery-MediumItalic")
860 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
861 ;; (w3-table-hack-x-face . "LineDrawNormal"))
862 ;; (size . 10.0)
863 ;; (line-height . 10.55)
864 ;; (space-width . 6.0)
865 ;; (avg-char-width . 6.0))
867 ;; Now you can use your new font family with any size:
868 ;; (setq ps-font-family 'my-mixed-family)
870 ;; Note that on above example the `w3-table-hack-x-face' entry refers to
871 ;; a face symbol, so when printing this face it'll be used the font
872 ;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
873 ;; use bold and/or italic attribute, the corresponding entry (bold, italic
874 ;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
876 ;; Note also that the font family entry order is irrelevant, so the above
877 ;; example could also be written:
878 ;; (my-mixed-family
879 ;; (size . 10.0)
880 ;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
881 ;; (bold . "Helvetica")
882 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
883 ;; (italic . "Zapf-Chancery-MediumItalic")
884 ;; (normal . "Courier-Bold"))
885 ;; (avg-char-width . 6.0)
886 ;; (space-width . 6.0)
887 ;; (line-height . 10.55))
889 ;; Despite the note above, it is recommended that some convention about
890 ;; entry order be used.
892 ;; You can get information on all the fonts resident in YOUR printer
893 ;; by uncommenting the line:
894 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
896 ;; The PostScript file should be sent to YOUR PostScript printer.
897 ;; If you send it to ghostscript or to another PostScript printer,
898 ;; you may get slightly different results.
899 ;; Anyway, as ghostscript fonts are autoload, you won't get
900 ;; much font info.
903 ;; How Ps-Print Deals With Faces
904 ;; -----------------------------
906 ;; The ps-print-*-with-faces commands attempt to determine which faces
907 ;; should be printed in bold or italic, but their guesses aren't
908 ;; always right. For example, you might want to map colors into faces
909 ;; so that blue faces print in bold, and red faces in italic.
911 ;; It is possible to force ps-print to consider specific faces bold,
912 ;; italic or underline, no matter what font they are displayed in, by setting
913 ;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
914 ;; These variables contain lists of faces that ps-print should consider bold,
915 ;; italic or underline; to set them, put code like the following into your
916 ;; .emacs file:
918 ;; (setq ps-bold-faces '(my-blue-face))
919 ;; (setq ps-italic-faces '(my-red-face))
920 ;; (setq ps-underlined-faces '(my-green-face))
922 ;; Faces like bold-italic that are both bold and italic should go in
923 ;; *both* lists.
925 ;; ps-print keeps internal lists of which fonts are bold and which are
926 ;; italic; these lists are built the first time you invoke ps-print.
927 ;; For the sake of efficiency, the lists are built only once; the same
928 ;; lists are referred in later invocations of ps-print.
930 ;; Because these lists are built only once, it's possible for them to
931 ;; get out of sync, if a face changes, or if new faces are added. To
932 ;; get the lists back in sync, you can set the variable
933 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
934 ;; next time ps-print is invoked. If you need that the lists always be
935 ;; rebuilt when ps-print is invoked, set the variable
936 ;; `ps-always-build-face-reference' to t.
938 ;; If you need to print without worrying about face background color, set the
939 ;; variable `ps-use-face-background' which specifies if face background should
940 ;; be used. Valid values are:
942 ;; t always use face background color.
943 ;; nil never use face background color.
944 ;; (face...) list of faces whose background color will be used.
946 ;; Any other value will be treated as t.
947 ;; The default value is t.
950 ;; How Ps-Print Deals With Color
951 ;; -----------------------------
953 ;; ps-print detects faces with foreground and background colors
954 ;; defined and embeds color information in the PostScript image.
955 ;; The default foreground and background colors are defined by the
956 ;; variables `ps-default-fg' and `ps-default-bg'.
957 ;; On black-and-white printers, colors are displayed in gray scale.
958 ;; To turn off color output, set `ps-print-color-p' to nil.
961 ;; How Ps-Print Maps Faces
962 ;; -----------------------
964 ;; As ps-print uses PostScript to print buffers, it is possible to have
965 ;; other attributes associated with faces. So the new attributes used
966 ;; by ps-print are:
968 ;; strikeout - like underline, but the line is in middle of text.
969 ;; overline - like underline, but the line is over the text.
970 ;; shadow - text will have a shadow.
971 ;; box - text will be surrounded by a box.
972 ;; outline - print characters as hollow outlines.
974 ;; See the documentation for `ps-extend-face'.
976 ;; Let's, for example, remap `font-lock-keyword-face' to another foreground
977 ;; color and bold attribute:
979 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
981 ;; If you want to use a new face, define it first with `defface',
982 ;; and then call `ps-extend-face' to specify how to print it.
985 ;; How Ps-Print Has A Text And/Or Image On Background
986 ;; --------------------------------------------------
988 ;; ps-print can print texts and/or EPS PostScript images on background; it is
989 ;; possible to define the following text attributes: font name, font size,
990 ;; initial position, angle, gray scale and pages to print.
992 ;; It has the following EPS PostScript images attributes: file name containing
993 ;; the image, initial position, X and Y scales, angle and pages to print.
995 ;; See documentation for `ps-print-background-text' and
996 ;; `ps-print-background-image'.
998 ;; For example, if we wish to print text "preliminary" on all pages and text
999 ;; "special" on page 5 and from page 11 to page 17, we could specify:
1001 ;; (setq ps-print-background-text
1002 ;; '(("preliminary")
1003 ;; ("special"
1004 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
1005 ;; ; (upper left corner)
1006 ;; nil nil nil
1007 ;; "PrintHeight neg PrintPageWidth atan" ; angle
1008 ;; 5 (11 . 17)) ; page list
1009 ;; ))
1011 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
1012 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
1013 ;; specify:
1015 ;; (setq ps-print-background-image
1016 ;; '(("~/images/EPS-image1.ps"
1017 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
1018 ;; ("~/images/EPS-image2.ps"
1019 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
1020 ;; ; (upper left corner)
1021 ;; nil nil nil
1022 ;; 5 (11 . 17)) ; page list
1023 ;; ))
1025 ;; If it is not possible to read (or does not exist) an image file, that file
1026 ;; is ignored.
1028 ;; The printing order is:
1030 ;; 1. Print background color
1031 ;; 2. Print zebra stripes
1032 ;; 3. Print background texts that it should be on all pages
1033 ;; 4. Print background images that it should be on all pages
1034 ;; 5. Print background texts only for current page (if any)
1035 ;; 6. Print background images only for current page (if any)
1036 ;; 7. Print header
1037 ;; 8. Print buffer text (with faces, if specified) and line number
1040 ;; Utilities
1041 ;; ---------
1043 ;; Some tools are provided to help you customize your font setup.
1045 ;; `ps-setup' returns (some part of) the current setup.
1047 ;; To avoid wrapping too many lines, you may want to adjust the
1048 ;; left and right margins and the font size. On UN*X systems, do:
1049 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
1050 ;; to determine the longest lines of your file.
1051 ;; Then, the command `ps-line-lengths' will give you the correspondence
1052 ;; between a line length (number of characters) and the maximum font
1053 ;; size which doesn't wrap such a line with the current ps-print setup.
1055 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
1056 ;; the correspondence between a number of pages and the maximum font
1057 ;; size which allow the number of lines of the current buffer or of
1058 ;; its current region to fit in this number of pages.
1060 ;; NOTE: line folding is not taken into account in this process and could
1061 ;; change the results.
1063 ;; The command `ps-print-customize' activates a customization buffer for
1064 ;; ps-print options.
1067 ;; New since version 1.5
1068 ;; ---------------------
1070 ;; Color output capability.
1071 ;; Automatic detection of font attributes (bold, italic).
1072 ;; Configurable headers with page numbers.
1073 ;; Slightly faster.
1074 ;; Support for different paper sizes.
1075 ;; Better conformance to PostScript Document Structure Conventions.
1078 ;; New since version 2.8
1079 ;; ---------------------
1081 ;; [vinicius] Vinicius Jose Latorre <vinicius@cpqd.com.br>
1083 ;; 20000617
1084 ;; `ps-manual-feed', `ps-warn-paper-type', `ps-print-upside-down',
1085 ;; `ps-selected-pages', `ps-last-selected-pages',
1086 ;; `ps-restore-selected-pages', `ps-switch-header',
1087 ;; `ps-line-number-step', `ps-line-number-start',
1088 ;; `ps-zebra-stripe-follow' and `ps-use-face-background'.
1090 ;; 20000310
1091 ;; PostScript error handler.
1092 ;; `ps-user-defined-prologue' and `ps-error-handler-message'.
1094 ;; 991211
1095 ;; `ps-print-customize'.
1097 ;; 990703
1098 ;; Better customization.
1099 ;; `ps-banner-page-when-duplexing' and `ps-zebra-color'.
1101 ;; 990513
1102 ;; N-up printing.
1103 ;; Hook: `ps-print-begin-sheet-hook'.
1105 ;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
1107 ;; `ps-print-region-function'
1109 ;; [vinicius] Vinicius Jose Latorre <vinicius@cpqd.com.br>
1111 ;; 990301
1112 ;; PostScript tumble and setpagedevice.
1114 ;; 980922
1115 ;; PostScript prologue header comment insertion.
1116 ;; Skip invisible text better.
1118 ;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
1120 ;; Multi-byte buffer handling.
1122 ;; [vinicius] Vinicius Jose Latorre <vinicius@cpqd.com.br>
1124 ;; 980306
1125 ;; Skip invisible text.
1127 ;; 971130
1128 ;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
1129 ;; `ps-print-begin-column-hook'.
1130 ;; Put one header per page over the columns.
1131 ;; Better database font management.
1132 ;; Better control characters handling.
1134 ;; 971121
1135 ;; Dynamic evaluation at print time of `ps-lpr-switches'.
1136 ;; Handle control characters.
1137 ;; Face remapping.
1138 ;; New face attributes.
1139 ;; Line number.
1140 ;; Zebra stripes.
1141 ;; Text and/or image on background.
1143 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
1145 ;; Font family and float size for text and header.
1146 ;; Landscape mode.
1147 ;; Multiple columns.
1148 ;; Tools for page setup.
1151 ;; Known bugs and limitations of ps-print
1152 ;; --------------------------------------
1154 ;; Although color printing will work in XEmacs 19.12, it doesn't work
1155 ;; well; in particular, bold or italic fonts don't print in the right
1156 ;; background color.
1158 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
1160 ;; Automatic font-attribute detection doesn't work well, especially
1161 ;; with hilit19 and older versions of get-create-face. Users having
1162 ;; problems with auto-font detection should use the lists
1163 ;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
1164 ;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
1166 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
1167 ;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
1168 ;; `ps-underlined-faces' instead.
1170 ;; Still too slow; could use some hand-optimization.
1172 ;; Default background color isn't working.
1174 ;; Faces are always treated as opaque.
1176 ;; Epoch and Emacs 19 not supported. At all.
1178 ;; Fixed-pitch fonts work better for line folding, but are not required.
1180 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
1181 ;; of folding lines.
1184 ;; Things to change
1185 ;; ----------------
1187 ;; Avoid page break inside a paragraph.
1188 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
1189 ;; Improve the memory management for big files (hard?).
1190 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1191 ;; of folding lines.
1194 ;; Acknowledgements
1195 ;; ----------------
1197 ;; Thanks to Paul Furnanz <pfurnanz@synopsys.com> for XEmacs compatibility
1198 ;; suggestion for `ps-postscript-code-directory' variable.
1200 ;; Thanks to David X Callaway <dxc@xprt.net> for helping debugging PostScript
1201 ;; level 1 compatibility.
1203 ;; Thanks to Colin Marquardt <colin.marquardt@usa.alcatel.com> for upside-down,
1204 ;; line number step, line number start and zebra stripe follow suggestions, and
1205 ;; for XEmacs beta-tests.
1207 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for user defined PostScript
1208 ;; prologue code suggestion.
1210 ;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
1212 ;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1213 ;; empty columns.
1215 ;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1216 ;; last page.
1218 ;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1219 ;; `ps-print-control-characters' variable documentation.
1221 ;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1222 ;; database font management.
1224 ;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
1225 ;; header per page over the columns and correct line numbers when printing a
1226 ;; region.
1228 ;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1229 ;; print time of `ps-lpr-switches'.
1231 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1232 ;; (his code was severely modified, but the main idea was kept).
1234 ;; Thanks to some suggestions on:
1235 ;; * Face color map: Marco Melgazzi <marco@techie.com>
1236 ;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
1237 ;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
1239 ;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1240 ;; I started from. [vinicius]
1242 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1243 ;; [jack]
1245 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1246 ;; color and the invisible property.
1248 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1249 ;; the initial port to Emacs 19. His code is no longer part of
1250 ;; ps-print, but his work is still appreciated.
1252 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1253 ;; for adding underline support. Their code also is no longer part of
1254 ;; ps-print, but their efforts are not forgotten.
1256 ;; Thanks also to all of you who mailed code to add features to
1257 ;; ps-print; although I didn't use your code, I still appreciate your
1258 ;; sharing it with me.
1260 ;; Thanks to all who mailed comments, encouragement, and criticism.
1261 ;; Thanks also to all who responded to my survey; I had too many
1262 ;; responses to reply to them all, but I greatly appreciate your
1263 ;; interest.
1265 ;; Jim
1266 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1268 ;;; Code:
1270 (unless (featurep 'lisp-float-type)
1271 (error "`ps-print' requires floating point support"))
1274 ;; For Emacs 20.2 and the earlier version.
1276 (or (fboundp 'set-buffer-multibyte)
1277 (defun set-buffer-multibyte (arg)
1278 (setq enable-multibyte-characters arg)))
1280 (or (fboundp 'string-as-unibyte)
1281 (defun string-as-unibyte (arg) arg))
1283 (or (fboundp 'string-as-multibyte)
1284 (defun string-as-multibyte (arg) arg))
1286 (or (fboundp 'charset-after)
1287 (defun charset-after (&optional arg)
1288 (char-charset (char-after arg))))
1291 ;; GNU Emacs
1292 (or (fboundp 'line-beginning-position)
1293 (defun line-beginning-position (&optional n)
1294 (save-excursion
1295 (and n (/= n 1) (forward-line (1- n)))
1296 (beginning-of-line)
1297 (point))))
1300 ;; to avoid compilation gripes
1301 (eval-and-compile
1302 (mapcar #'(lambda (sym)
1303 (or (fboundp sym)
1304 (defalias sym 'ignore)))
1305 '(;; XEmacs
1306 color-instance-p
1307 color-instance-rgb-components
1308 color-name
1309 color-specifier-p
1310 copy-coding-system
1311 device-class
1312 extent-end-position
1313 extent-face
1314 extent-priority
1315 extent-start-position
1316 face-font-instance
1317 find-coding-system
1318 font-instance-properties
1319 make-color-instance
1320 map-extents)))
1323 (defconst ps-windows-system
1324 (memq system-type '(emx win32 w32 mswindows ms-dos windows-nt)))
1325 (defconst ps-lp-system
1326 (memq system-type '(usq-unix-v dgux hpux irix)))
1329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1330 ;; User Variables:
1333 ;;; Interface to the command system
1335 (defgroup postscript nil
1336 "PostScript Group"
1337 :tag "PostScript"
1338 :group 'emacs)
1340 (defgroup ps-print nil
1341 "PostScript generator for Emacs 19"
1342 :prefix "ps-"
1343 :group 'wp
1344 :group 'postscript)
1346 (defgroup ps-print-horizontal nil
1347 "Horizontal page layout"
1348 :prefix "ps-"
1349 :tag "Horizontal"
1350 :group 'ps-print)
1352 (defgroup ps-print-vertical nil
1353 "Vertical page layout"
1354 :prefix "ps-"
1355 :tag "Vertical"
1356 :group 'ps-print)
1358 (defgroup ps-print-headers nil
1359 "Headers layout"
1360 :prefix "ps-"
1361 :tag "Header"
1362 :group 'ps-print)
1364 (defgroup ps-print-font nil
1365 "Fonts customization"
1366 :prefix "ps-"
1367 :tag "Font"
1368 :group 'ps-print)
1370 (defgroup ps-print-color nil
1371 "Color customization"
1372 :prefix "ps-"
1373 :tag "Color"
1374 :group 'ps-print)
1376 (defgroup ps-print-face nil
1377 "Faces customization"
1378 :prefix "ps-"
1379 :tag "PS Faces"
1380 :group 'ps-print
1381 :group 'faces)
1383 (defgroup ps-print-n-up nil
1384 "N-up customization"
1385 :prefix "ps-"
1386 :tag "N-Up"
1387 :group 'ps-print)
1389 (defgroup ps-print-zebra nil
1390 "Zebra customization"
1391 :prefix "ps-"
1392 :tag "Zebra"
1393 :group 'ps-print)
1395 (defgroup ps-print-background nil
1396 "Background customization"
1397 :prefix "ps-"
1398 :tag "Background"
1399 :group 'ps-print)
1401 (defgroup ps-print-printer nil
1402 "Printer customization"
1403 :prefix "ps-"
1404 :tag "Printer"
1405 :group 'ps-print)
1407 (defgroup ps-print-page nil
1408 "Page customization"
1409 :prefix "ps-"
1410 :tag "Page"
1411 :group 'ps-print)
1413 (defgroup ps-print-miscellany nil
1414 "Miscellany customization"
1415 :prefix "ps-"
1416 :tag "Miscellany"
1417 :group 'ps-print)
1420 (defcustom ps-error-handler-message 'paper
1421 "*Specify where the error handler message should be sent.
1423 Valid values are:
1425 `none' catch the error and *DON'T* send any message.
1427 `paper' catch the error and print on paper the error message.
1429 `system' catch the error and send back the error message to
1430 printing system. This is useful only if printing system
1431 send back an email reporting the error, or if there is
1432 some other alternative way to report back the error from
1433 the system to you.
1435 `paper-and-system' catch the error, print on paper the error message and
1436 send back the error message to printing system.
1438 Any other value is treated as `paper'."
1439 :type '(choice :menu-tag "Error Handler Message"
1440 :tag "Error Handler Message"
1441 (const none) (const paper)
1442 (const system) (const paper-and-system))
1443 :group 'ps-print-miscellany)
1445 (defcustom ps-user-defined-prologue nil
1446 "*User defined PostScript prologue code inserted before all prologue code.
1448 `ps-user-defined-prologue' may be a string or a symbol function which returns a
1449 string. Note that this string is inserted after `ps-adobe-tag' and PostScript
1450 prologue comments, and before ps-print PostScript prologue code section. That
1451 is, this string is inserted after error handler initialization and before
1452 ps-print settings.
1454 It's recommended to initiate and terminate the string with \"\\n\".
1456 It's strongly recommended only insert PostScript code and/or comments specific
1457 for your printing system particularities. For example, some special
1458 initialization that only your printing system needs.
1460 Do not insert code for duplex printing, n-up printing or error handler, ps-print
1461 handles this in a suitable way.
1463 For more information about PostScript, see:
1464 PostScript Language Reference Manual (2nd edition)
1465 Adobe Systems Incorporated"
1466 :type '(choice :menu-tag "User Defined Prologue"
1467 :tag "User Defined Prologue"
1468 (const :tag "none" nil) string symbol)
1469 :group 'ps-print-miscellany)
1471 (defcustom ps-print-prologue-header nil
1472 "*PostScript prologue header comments besides that ps-print generates.
1474 `ps-print-prologue-header' may be a string or a symbol function which
1475 returns a string. Note that this string is inserted on PostScript prologue
1476 header section which is used to define some document characteristic through
1477 PostScript special comments, like \"%%Requirements: jog\\n\".
1479 ps-print always inserts the %%Requirements: comment, so if you need to insert
1480 more requirements put them first in `ps-print-prologue-header' using the
1481 \"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1482 requirements and set %%LanguageLevel: to 2, do:
1484 (setq ps-print-prologue-header
1485 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1487 The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1489 Do not forget to terminate the string with \"\\n\".
1491 For more information about PostScript document comments, see:
1492 PostScript Language Reference Manual (2nd edition)
1493 Adobe Systems Incorporated
1494 Appendix G: Document Structuring Conventions -- Version 3.0"
1495 :type '(choice :menu-tag "Prologue Header"
1496 :tag "Prologue Header"
1497 (const :tag "none" nil) string symbol)
1498 :group 'ps-print-miscellany)
1500 (defcustom ps-printer-name (and (boundp 'printer-name)
1501 printer-name)
1502 "*The name of a local printer for printing PostScript files.
1504 On Unix-like systems, a string value should be a name understood by
1505 lpr's -P option; a value of nil means use the value of `printer-name'
1506 instead. Any other value will be ignored.
1508 On MS-DOS and MS-Windows systems, a string value is taken as the name of
1509 the printer device or port to which PostScript files are written,
1510 provided `ps-lpr-command' is \"\". By default it is the same as
1511 `printer-name'; typical non-default settings would be \"LPT1\" to
1512 \"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1513 serial printers, or \"//hostname/printer\" for a shared network printer.
1514 You can also set it to a name of a file, in which case the output gets
1515 appended to that file. \(Note that `ps-print' package already has
1516 facilities for printing to a file, so you might as well use them instead
1517 of changing the setting of this variable.\) If you want to silently
1518 discard the printed output, set this to \"NUL\"."
1519 :type '(choice :menu-tag "Printer Name"
1520 :tag "Printer Name"
1521 (const :tag "Same as printer-name" nil)
1522 (file :tag "Print to file")
1523 (string :tag "Pipe to ps-lpr-command"))
1524 :group 'ps-print-printer)
1526 (defcustom ps-lpr-command lpr-command
1527 "*Name of program for printing a PostScript file.
1529 On MS-DOS and MS-Windows systems, if the value is an empty string then
1530 Emacs will write directly to the printer port named by `ps-printer-name'.
1531 The programs `print' and `nprint' (the standard print programs on Windows
1532 NT and Novell Netware respectively) are handled specially, using
1533 `ps-printer-name' as the destination for output; any other program is
1534 treated like `lpr' except that an explicit filename is given as the last
1535 argument."
1536 :type 'string
1537 :group 'ps-print-printer)
1539 (defcustom ps-lpr-switches lpr-switches
1540 "*A list of extra switches to pass to `ps-lpr-command'."
1541 :type '(repeat :tag "PostScript lpr Switches"
1542 (choice string symbol (repeat sexp)))
1543 :group 'ps-print-printer)
1545 (defcustom ps-print-region-function nil
1546 "*Specify a function to print the region on a PostScript printer.
1547 See definition of `call-process-region' for calling conventions. The fourth and
1548 the sixth arguments are both nil."
1549 :type 'function
1550 :group 'ps-print-printer)
1552 (defcustom ps-manual-feed nil
1553 "*Non-nil means the printer will manually feed paper.
1555 If it's nil, automatic feeding takes place."
1556 :type 'boolean
1557 :group 'ps-print-printer)
1559 ;;; Page layout
1561 ;; All page dimensions are in PostScript points.
1562 ;; 1 inch == 2.54 cm == 72 points
1563 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1565 ;; Letter 8.5 inch x 11.0 inch
1566 ;; Legal 8.5 inch x 14.0 inch
1567 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1569 ;; LetterSmall 7.68 inch x 10.16 inch
1570 ;; Tabloid 11.0 inch x 17.0 inch
1571 ;; Ledger 17.0 inch x 11.0 inch
1572 ;; Statement 5.5 inch x 8.5 inch
1573 ;; Executive 7.5 inch x 10.0 inch
1574 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1575 ;; A4Small 7.47 inch x 10.85 inch
1576 ;; B4 10.125 inch x 14.33 inch
1577 ;; B5 7.16 inch x 10.125 inch
1579 (defcustom ps-page-dimensions-database
1580 (list (list 'a4 (/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1581 (list 'a3 (/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1582 (list 'letter (* 72 8.5) (* 72 11.0) "Letter")
1583 (list 'legal (* 72 8.5) (* 72 14.0) "Legal")
1584 (list 'letter-small (* 72 7.68) (* 72 10.16) "LetterSmall")
1585 (list 'tabloid (* 72 11.0) (* 72 17.0) "Tabloid")
1586 (list 'ledger (* 72 17.0) (* 72 11.0) "Ledger")
1587 (list 'statement (* 72 5.5) (* 72 8.5) "Statement")
1588 (list 'executive (* 72 7.5) (* 72 10.0) "Executive")
1589 (list 'a4small (* 72 7.47) (* 72 10.85) "A4Small")
1590 (list 'b4 (* 72 10.125) (* 72 14.33) "B4")
1591 (list 'b5 (* 72 7.16) (* 72 10.125) "B5"))
1592 "*List associating a symbolic paper type to its width, height and doc media.
1593 See `ps-paper-type'."
1594 :type '(repeat (list :tag "Paper Type"
1595 (symbol :tag "Name")
1596 (number :tag "Width")
1597 (number :tag "Height")
1598 (string :tag "Media")))
1599 :group 'ps-print-page)
1601 ;;;###autoload
1602 (defcustom ps-paper-type 'letter
1603 "*Specify the size of paper to format for.
1604 Should be one of the paper types defined in `ps-page-dimensions-database', for
1605 example `letter', `legal' or `a4'."
1606 :type '(symbol :validate (lambda (wid)
1607 (if (assq (widget-value wid)
1608 ps-page-dimensions-database)
1610 (widget-put wid :error "Unknown paper size")
1611 wid)))
1612 :group 'ps-print-page)
1614 (defcustom ps-warn-paper-type t
1615 "*Non-nil means give an error if paper size is not equal to `ps-paper-type'.
1617 It's used when `ps-spool-config' is set to `setpagedevice'."
1618 :type 'boolean
1619 :group 'ps-print-page)
1621 (defcustom ps-landscape-mode nil
1622 "*Non-nil means print in landscape mode."
1623 :type 'boolean
1624 :group 'ps-print-page)
1626 (defcustom ps-print-upside-down nil
1627 "*Non-nil means print upside-down."
1628 :type 'boolean
1629 :group 'ps-print-page)
1631 (defcustom ps-selected-pages nil
1632 "*Specify which pages to print.
1634 If it's nil, all pages are printed.
1636 If it's a list, the list element may be an integer or a cons cell (FROM . TO)
1637 designating FROM page to TO page; any invalid element is ignored, that is, an
1638 integer lesser than one or if FROM is greater than TO.
1640 Otherwise, it's treated as nil.
1642 After ps-print processing `ps-selected-pages' is set to nil. But the latest
1643 `ps-selected-pages' is saved in `ps-last-selected-pages' (see it for
1644 documentation). So you can restore the latest selected pages by using
1645 `ps-last-selected-pages' or by calling `ps-restore-selected-pages' command (see
1646 it for documentation)."
1647 :type '(repeat :tag "Selected Pages"
1648 (radio :tag "Page"
1649 (integer :tag "Number")
1650 (cons :tag "Range"
1651 (integer :tag "From")
1652 (integer :tag "To"))))
1653 :group 'ps-print-page)
1655 (defcustom ps-print-control-characters 'control-8-bit
1656 "*Specify the printable form for control and 8-bit characters.
1657 That is, instead of sending, for example, a ^D (\\004) to printer,
1658 it is sent the string \"^D\".
1660 Valid values are:
1662 `8-bit' This is the value to use when you want an ASCII encoding of
1663 any control or non-ASCII character. Control characters are
1664 encoded as \"^D\", and non-ASCII characters have an
1665 octal encoding.
1667 `control-8-bit' This is the value to use when you want an ASCII encoding of
1668 any control character, whether it is 7 or 8-bit.
1669 European 8-bits accented characters are printed according
1670 the current font.
1672 `control' Only ASCII control characters have an ASCII encoding.
1673 European 8-bits accented characters are printed according
1674 the current font.
1676 nil No ASCII encoding. Any character is printed according the
1677 current font.
1679 Any other value is treated as nil."
1680 :type '(choice :menu-tag "Control Char"
1681 :tag "Control Char"
1682 (const 8-bit) (const control-8-bit)
1683 (const control) (const :tag "nil" nil))
1684 :group 'ps-print-miscellany)
1686 (defcustom ps-n-up-printing 1
1687 "*Specify the number of pages per sheet paper."
1688 :type '(integer
1689 :tag "N Up Printing"
1690 :validate
1691 (lambda (wid)
1692 (if (and (< 0 (widget-value wid))
1693 (<= (widget-value wid) 100))
1695 (widget-put
1696 wid :error
1697 "Number of pages per sheet paper must be between 1 and 100.")
1698 wid)))
1699 :group 'ps-print-n-up)
1701 (defcustom ps-n-up-margin (/ (* 72 1.0) 2.54) ; 1 cm
1702 "*Specify the margin in points between the sheet border and n-up printing."
1703 :type 'number
1704 :group 'ps-print-n-up)
1706 (defcustom ps-n-up-border-p t
1707 "*Non-nil means a border is drawn around each page."
1708 :type 'boolean
1709 :group 'ps-print-n-up)
1711 (defcustom ps-n-up-filling 'left-top
1712 "*Specify how page matrix is filled on each sheet of paper.
1714 Following are the valid values for `ps-n-up-filling' with a filling example
1715 using a 3x4 page matrix:
1717 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1718 5 6 7 8 5 6 7 8
1719 9 10 11 12 1 2 3 4
1721 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1722 8 7 6 5 8 7 6 5
1723 12 11 10 9 4 3 2 1
1725 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1726 2 5 8 11 2 5 8 11
1727 3 6 9 12 1 4 7 10
1729 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1730 11 8 5 2 11 8 5 2
1731 12 9 6 3 10 7 4 1
1733 Any other value is treated as `left-top'."
1734 :type '(choice :menu-tag "N-Up Filling"
1735 :tag "N-Up Filling"
1736 (const left-top) (const left-bottom)
1737 (const right-top) (const right-bottom)
1738 (const top-left) (const bottom-left)
1739 (const top-right) (const bottom-right))
1740 :group 'ps-print-n-up)
1742 (defcustom ps-number-of-columns (if ps-landscape-mode 2 1)
1743 "*Specify the number of columns"
1744 :type 'number
1745 :group 'ps-print-miscellany)
1747 (defcustom ps-zebra-stripes nil
1748 "*Non-nil means print zebra stripes.
1749 See also documentation for `ps-zebra-stripe-height' and `ps-zebra-color'."
1750 :type 'boolean
1751 :group 'ps-print-zebra)
1753 (defcustom ps-zebra-stripe-height 3
1754 "*Number of zebra stripe lines.
1755 See also documentation for `ps-zebra-stripes' and `ps-zebra-color'."
1756 :type 'number
1757 :group 'ps-print-zebra)
1759 (defcustom ps-zebra-color 0.95
1760 "*Zebra stripe gray scale or RGB color.
1761 See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
1762 :type '(choice :menu-tag "Zebra Gray/Color"
1763 :tag "Zebra Gray/Color"
1764 (number :tag "Gray Scale" :value 0.95)
1765 (string :tag "Color Name" :value "gray95")
1766 (list :tag "RGB Color" :value (0.95 0.95 0.95)
1767 (number :tag "Red")
1768 (number :tag "Green")
1769 (number :tag "Blue")))
1770 :group 'ps-print-zebra)
1772 (defcustom ps-zebra-stripe-follow nil
1773 "*Non-nil means zebra stripe continues on next page.
1775 If `ps-zebra-stripe-follow' is nil, zebra stripe is restarted on each page.
1776 If `ps-zebra-stripe-follow' is non-nil, zebra stripe continues on next page.
1778 Visually, we have:
1780 `ps-zebra-stripe-follow' `ps-zebra-stripe-follow'
1781 is nil is non-nil
1782 Current Page ------------------------ ------------------------
1783 1 XXXXXXXXXXXXXXXXXXXXX 1 XXXXXXXXXXXXXXXXXXXXX
1784 2 XXXXXXXXXXXXXXXXXXXXX 2 XXXXXXXXXXXXXXXXXXXXX
1785 3 XXXXXXXXXXXXXXXXXXXXX 3 XXXXXXXXXXXXXXXXXXXXX
1789 7 XXXXXXXXXXXXXXXXXXXXX 7 XXXXXXXXXXXXXXXXXXXXX
1790 8 XXXXXXXXXXXXXXXXXXXXX 8 XXXXXXXXXXXXXXXXXXXXX
1791 ------------------------ ------------------------
1792 Next Page ------------------------ ------------------------
1793 9 XXXXXXXXXXXXXXXXXXXXX 9 XXXXXXXXXXXXXXXXXXXXX
1794 10 XXXXXXXXXXXXXXXXXXXXX 10
1795 11 XXXXXXXXXXXXXXXXXXXXX 11
1796 12 12
1797 13 13 XXXXXXXXXXXXXXXXXXXXX
1798 14 14 XXXXXXXXXXXXXXXXXXXXX
1799 15 XXXXXXXXXXXXXXXXXXXXX 15 XXXXXXXXXXXXXXXXXXXXX
1800 16 XXXXXXXXXXXXXXXXXXXXX 16
1801 ------------------------ ------------------------"
1802 :type 'boolean
1803 :group 'ps-print-zebra)
1805 (defcustom ps-line-number nil
1806 "*Non-nil means print line number."
1807 :type 'boolean
1808 :group 'ps-print-miscellany)
1810 (defcustom ps-line-number-step 1
1811 "*Specify the interval that line number is printed.
1813 For example, `ps-line-number-step' is set to 2, the printing will look like:
1815 1 one line
1816 one line
1817 3 one line
1818 one line
1819 5 one line
1820 one line
1823 Valid values are:
1825 integer an integer that specifies the interval that line number is
1826 printed. If it's lesser than or equal to zero, it's used the
1827 value 1.
1829 `zebra' specifies that only the line number of the first line in a zebra
1830 stripe is to be printed.
1832 Any other value is treated as `zebra'."
1833 :type '(choice :menu-tag "Line Number Step"
1834 :tag "Line Number Step"
1835 (integer :tag "Step Interval")
1836 (const :tag "Synchronize Zebra" zebra))
1837 :group 'ps-print-miscellany)
1839 (defcustom ps-line-number-start 1
1840 "*Specify the starting point in the interval given by `ps-line-number-step'.
1842 For example, if `ps-line-number-step' is set to 3 and `ps-line-number-start' is set to 3, the
1843 printing will look like:
1845 one line
1846 one line
1847 3 one line
1848 one line
1849 one line
1850 6 one line
1851 one line
1852 one line
1853 9 one line
1854 one line
1857 The values for `ps-line-number-start':
1859 * If `ps-line-number-step' is an integer, must be between 1 and the value
1860 of `ps-line-number-step' inclusive.
1862 * If `ps-line-number-step' is set to `zebra', must be between 1 and the
1863 value of `ps-zebra-strip-height' inclusive. Use this combination if you
1864 wish that line number be relative to zebra stripes."
1865 :type '(integer :tag "Start Step Interval")
1866 :group 'ps-print-miscellany)
1868 (defcustom ps-print-background-image nil
1869 "*EPS image list to be printed on background.
1871 The elements are:
1873 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1875 FILENAME is a file name which contains an EPS image or some PostScript
1876 programming like EPS.
1877 FILENAME is ignored, if it doesn't exist or is read protected.
1879 X and Y are relative positions on paper to put the image.
1880 If X and Y are nil, the image is centralized on paper.
1882 XSCALE and YSCALE are scale factor to be applied to image before printing.
1883 If XSCALE and YSCALE are nil, the original size is used.
1885 ROTATION is the image rotation angle; if nil, the default is 0.
1887 PAGES designates the page to print background image.
1888 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1889 to TO page.
1890 If PAGES is nil, print background image on all pages.
1892 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1893 an integer number or a string. If it is a string, the string should contain
1894 PostScript programming that returns a float or integer value.
1896 For example, if you wish to print an EPS image on all pages do:
1898 '((\"~/images/EPS-image.ps\"))"
1899 :type '(repeat
1900 (list
1901 (file :tag "EPS File")
1902 (choice :tag "X" (const :tag "default" nil) number string)
1903 (choice :tag "Y" (const :tag "default" nil) number string)
1904 (choice :tag "X Scale" (const :tag "default" nil) number string)
1905 (choice :tag "Y Scale" (const :tag "default" nil) number string)
1906 (choice :tag "Rotation" (const :tag "default" nil) number string)
1907 (repeat :tag "Pages" :inline t
1908 (radio (integer :tag "Page")
1909 (cons :tag "Range"
1910 (integer :tag "From")
1911 (integer :tag "To"))))))
1912 :group 'ps-print-background)
1914 (defcustom ps-print-background-text nil
1915 "*Text list to be printed on background.
1917 The elements are:
1919 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1921 STRING is the text to be printed on background.
1923 X and Y are positions on paper to put the text.
1924 If X and Y are nil, the text is positioned at lower left corner.
1926 FONT is a font name to be used on printing the text.
1927 If nil, \"Times-Roman\" is used.
1929 FONTSIZE is font size to be used, if nil, 200 is used.
1931 GRAY is the text gray factor (should be very light like 0.8).
1932 If nil, the default is 0.85.
1934 ROTATION is the text rotation angle; if nil, the angle is given by
1935 the diagonal from lower left corner to upper right corner.
1937 PAGES designates the page to print background text.
1938 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1939 to TO page.
1940 If PAGES is nil, print background text on all pages.
1942 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1943 an integer number or a string. If it is a string, the string should contain
1944 PostScript programming that returns a float or integer value.
1946 For example, if you wish to print text \"Preliminary\" on all pages do:
1948 '((\"Preliminary\"))"
1949 :type '(repeat
1950 (list
1951 (string :tag "Text")
1952 (choice :tag "X" (const :tag "default" nil) number string)
1953 (choice :tag "Y" (const :tag "default" nil) number string)
1954 (choice :tag "Font" (const :tag "default" nil) string)
1955 (choice :tag "Fontsize" (const :tag "default" nil) number string)
1956 (choice :tag "Gray" (const :tag "default" nil) number string)
1957 (choice :tag "Rotation" (const :tag "default" nil) number string)
1958 (repeat :tag "Pages" :inline t
1959 (radio (integer :tag "Page")
1960 (cons :tag "Range"
1961 (integer :tag "From")
1962 (integer :tag "To"))))))
1963 :group 'ps-print-background)
1965 ;;; Horizontal layout
1967 ;; ------------------------------------------
1968 ;; | | | | | | | |
1969 ;; | lm | text | ic | text | ic | text | rm |
1970 ;; | | | | | | | |
1971 ;; ------------------------------------------
1973 (defcustom ps-left-margin (/ (* 72 2.0) 2.54) ; 2 cm
1974 "*Left margin in points (1/72 inch)."
1975 :type 'number
1976 :group 'ps-print-horizontal)
1978 (defcustom ps-right-margin (/ (* 72 2.0) 2.54) ; 2 cm
1979 "*Right margin in points (1/72 inch)."
1980 :type 'number
1981 :group 'ps-print-horizontal)
1983 (defcustom ps-inter-column (/ (* 72 2.0) 2.54) ; 2 cm
1984 "*Horizontal space between columns in points (1/72 inch)."
1985 :type 'number
1986 :group 'ps-print-horizontal)
1988 ;;; Vertical layout
1990 ;; |--------|
1991 ;; | tm |
1992 ;; |--------|
1993 ;; | header |
1994 ;; |--------|
1995 ;; | ho |
1996 ;; |--------|
1997 ;; | text |
1998 ;; |--------|
1999 ;; | bm |
2000 ;; |--------|
2002 (defcustom ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
2003 "*Bottom margin in points (1/72 inch)."
2004 :type 'number
2005 :group 'ps-print-vertical)
2007 (defcustom ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
2008 "*Top margin in points (1/72 inch)."
2009 :type 'number
2010 :group 'ps-print-vertical)
2012 (defcustom ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
2013 "*Vertical space in points (1/72 inch) between the main text and the header."
2014 :type 'number
2015 :group 'ps-print-vertical)
2017 (defcustom ps-header-line-pad 0.15
2018 "*Portion of a header title line height to insert between the header frame
2019 and the text it contains, both in the vertical and horizontal directions."
2020 :type 'number
2021 :group 'ps-print-vertical)
2023 ;;; Header setup
2025 (defcustom ps-print-header t
2026 "*Non-nil means print a header at the top of each page.
2027 By default, the header displays the buffer name, page number, and, if
2028 the buffer is visiting a file, the file's directory. Headers are
2029 customizable by changing variables `ps-left-header' and
2030 `ps-right-header'."
2031 :type 'boolean
2032 :group 'ps-print-headers)
2034 (defcustom ps-print-only-one-header nil
2035 "*Non-nil means print only one header at the top of each page.
2036 This is useful when printing more than one column, so it is possible
2037 to have only one header over all columns or one header per column.
2038 See also `ps-print-header'."
2039 :type 'boolean
2040 :group 'ps-print-headers)
2042 (defcustom ps-print-header-frame t
2043 "*Non-nil means draw a gaudy frame around the header."
2044 :type 'boolean
2045 :group 'ps-print-headers)
2047 (defcustom ps-header-lines 2
2048 "*Number of lines to display in page header, when generating PostScript."
2049 :type 'integer
2050 :group 'ps-print-headers)
2052 (defcustom ps-switch-header 'duplex
2053 "*Specify if headers are switched or not.
2055 Valid values are:
2057 nil Never switch headers.
2059 t Always switch headers.
2061 duplex Switch headers only when duplexing is on, that is, when
2062 `ps-spool-duplex' is non-nil.
2064 Any other value is treated as t."
2065 :type '(choice :menu-tag "Switch Header"
2066 :tag "Switch Header"
2067 (const :tag "Never Switch" nil)
2068 (const :tag "Always Switch" t)
2069 (const :tag "Switch When Duplexing" duplex))
2070 :group 'ps-print-headers)
2072 (defcustom ps-show-n-of-n t
2073 "*Non-nil means show page numbers as N/M, meaning page N of M.
2074 NOTE: page numbers are displayed as part of headers,
2075 see variable `ps-print-header'."
2076 :type 'boolean
2077 :group 'ps-print-headers)
2079 (defcustom ps-spool-config
2080 (if ps-windows-system
2082 'lpr-switches)
2083 "*Specify who is responsable for setting duplex and page size switches.
2085 Valid values are:
2087 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
2088 Don't forget to set `ps-lpr-switches' to select duplex
2089 printing for your printer.
2091 `setpagedevice' duplex and page size are configured by ps-print using the
2092 setpagedevice PostScript operator.
2094 nil duplex and page size are configured by ps-print *not* using
2095 the setpagedevice PostScript operator.
2097 Any other value is treated as nil.
2099 WARNING: The setpagedevice PostScript operator affects ghostview utility when
2100 viewing file generated using landscape. Also on some printers,
2101 setpagedevice affects zebra stripes; on other printers, setpagedevice
2102 affects the left margin.
2103 Besides all that, if your printer does not have the paper size
2104 specified by setpagedevice, your printing will be aborted.
2105 So, if you need to use setpagedevice, set `ps-spool-config' to
2106 `setpagedevice', generate a test file and send it to your printer; if
2107 the printed file isn't ok, set `ps-spool-config' to nil."
2108 :type '(choice :menu-tag "Spool Config"
2109 :tag "Spool Config"
2110 (const lpr-switches) (const setpagedevice)
2111 (const :tag "nil" nil))
2112 :group 'ps-print-headers)
2114 (defcustom ps-spool-duplex nil ; Not many people have duplex printers,
2115 ; so default to nil.
2116 "*Non-nil generates PostScript for a two-sided printer.
2117 For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
2118 blank pages as needed between print jobs so that the next buffer printed will
2119 start on the right page. Also, if headers are turned on, the headers will be
2120 reversed on duplex printers so that the page numbers fall to the left on
2121 even-numbered pages.
2123 See also `ps-spool-tumble'."
2124 :type 'boolean
2125 :group 'ps-print-headers)
2127 (defcustom ps-spool-tumble nil
2128 "*Specify how the page images on opposite sides of a sheet are oriented.
2129 If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
2130 right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
2131 the top or bottom.
2133 It has effect only when `ps-spool-duplex' is non-nil."
2134 :type 'boolean
2135 :group 'ps-print-headers)
2137 ;;; Fonts
2139 (defcustom ps-font-info-database
2140 '((Courier ; the family key
2141 (fonts (normal . "Courier")
2142 (bold . "Courier-Bold")
2143 (italic . "Courier-Oblique")
2144 (bold-italic . "Courier-BoldOblique"))
2145 (size . 10.0)
2146 (line-height . 10.55)
2147 (space-width . 6.0)
2148 (avg-char-width . 6.0))
2149 (Helvetica ; the family key
2150 (fonts (normal . "Helvetica")
2151 (bold . "Helvetica-Bold")
2152 (italic . "Helvetica-Oblique")
2153 (bold-italic . "Helvetica-BoldOblique"))
2154 (size . 10.0)
2155 (line-height . 11.56)
2156 (space-width . 2.78)
2157 (avg-char-width . 5.09243))
2158 (Times
2159 (fonts (normal . "Times-Roman")
2160 (bold . "Times-Bold")
2161 (italic . "Times-Italic")
2162 (bold-italic . "Times-BoldItalic"))
2163 (size . 10.0)
2164 (line-height . 11.0)
2165 (space-width . 2.5)
2166 (avg-char-width . 4.71432))
2167 (Palatino
2168 (fonts (normal . "Palatino-Roman")
2169 (bold . "Palatino-Bold")
2170 (italic . "Palatino-Italic")
2171 (bold-italic . "Palatino-BoldItalic"))
2172 (size . 10.0)
2173 (line-height . 12.1)
2174 (space-width . 2.5)
2175 (avg-char-width . 5.08676))
2176 (Helvetica-Narrow
2177 (fonts (normal . "Helvetica-Narrow")
2178 (bold . "Helvetica-Narrow-Bold")
2179 (italic . "Helvetica-Narrow-Oblique")
2180 (bold-italic . "Helvetica-Narrow-BoldOblique"))
2181 (size . 10.0)
2182 (line-height . 11.56)
2183 (space-width . 2.2796)
2184 (avg-char-width . 4.17579))
2185 (NewCenturySchlbk
2186 (fonts (normal . "NewCenturySchlbk-Roman")
2187 (bold . "NewCenturySchlbk-Bold")
2188 (italic . "NewCenturySchlbk-Italic")
2189 (bold-italic . "NewCenturySchlbk-BoldItalic"))
2190 (size . 10.0)
2191 (line-height . 12.15)
2192 (space-width . 2.78)
2193 (avg-char-width . 5.31162))
2194 ;; got no bold for the next ones
2195 (AvantGarde-Book
2196 (fonts (normal . "AvantGarde-Book")
2197 (italic . "AvantGarde-BookOblique"))
2198 (size . 10.0)
2199 (line-height . 11.77)
2200 (space-width . 2.77)
2201 (avg-char-width . 5.45189))
2202 (AvantGarde-Demi
2203 (fonts (normal . "AvantGarde-Demi")
2204 (italic . "AvantGarde-DemiOblique"))
2205 (size . 10.0)
2206 (line-height . 12.72)
2207 (space-width . 2.8)
2208 (avg-char-width . 5.51351))
2209 (Bookman-Demi
2210 (fonts (normal . "Bookman-Demi")
2211 (italic . "Bookman-DemiItalic"))
2212 (size . 10.0)
2213 (line-height . 11.77)
2214 (space-width . 3.4)
2215 (avg-char-width . 6.05946))
2216 (Bookman-Light
2217 (fonts (normal . "Bookman-Light")
2218 (italic . "Bookman-LightItalic"))
2219 (size . 10.0)
2220 (line-height . 11.79)
2221 (space-width . 3.2)
2222 (avg-char-width . 5.67027))
2223 ;; got no bold and no italic for the next ones
2224 (Symbol
2225 (fonts (normal . "Symbol"))
2226 (size . 10.0)
2227 (line-height . 13.03)
2228 (space-width . 2.5)
2229 (avg-char-width . 3.24324))
2230 (Zapf-Dingbats
2231 (fonts (normal . "Zapf-Dingbats"))
2232 (size . 10.0)
2233 (line-height . 9.63)
2234 (space-width . 2.78)
2235 (avg-char-width . 2.78))
2236 (Zapf-Chancery-MediumItalic
2237 (fonts (normal . "Zapf-Chancery-MediumItalic"))
2238 (size . 10.0)
2239 (line-height . 11.45)
2240 (space-width . 2.2)
2241 (avg-char-width . 4.10811))
2243 "*Font info database: font family (the key), name, bold, italic, bold-italic,
2244 reference size, line height, space width, average character width.
2245 To get the info for another specific font (say Helvetica), do the following:
2246 - create a new buffer
2247 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
2248 - open this file and delete the leading `%' (which is the PostScript
2249 comment character) from the line
2250 `% 3 cm 20 cm moveto 10/Courier ReportFontInfo showpage'
2251 to get the line
2252 `3 cm 20 cm moveto 10/Helvetica ReportFontInfo showpage'
2253 - add the values to `ps-font-info-database'.
2254 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
2255 :type '(repeat (list :tag "Font Definition"
2256 (symbol :tag "Font Family")
2257 (cons :format "%v"
2258 (const :format "" fonts)
2259 (repeat :tag "Faces"
2260 (cons (choice (const normal)
2261 (const bold)
2262 (const italic)
2263 (const bold-italic)
2264 (symbol :tag "Face"))
2265 (string :tag "Font Name"))))
2266 (cons :format "%v"
2267 (const :format "" size)
2268 (number :tag "Reference Size"))
2269 (cons :format "%v"
2270 (const :format "" line-height)
2271 (number :tag "Line Height"))
2272 (cons :format "%v"
2273 (const :format "" space-width)
2274 (number :tag "Space Width"))
2275 (cons :format "%v"
2276 (const :format "" avg-char-width)
2277 (number :tag "Average Character Width"))))
2278 :group 'ps-print-font)
2280 (defcustom ps-font-family 'Courier
2281 "*Font family name for ordinary text, when generating PostScript."
2282 :type 'symbol
2283 :group 'ps-print-font)
2285 (defcustom ps-font-size '(7 . 8.5)
2286 "*Font size, in points, for ordinary text, when generating PostScript."
2287 :type '(choice (number :tag "Text Size")
2288 (cons :tag "Landscape/Portrait"
2289 (number :tag "Landscape Text Size")
2290 (number :tag "Portrait Text Size")))
2291 :group 'ps-print-font)
2293 (defcustom ps-header-font-family 'Helvetica
2294 "*Font family name for text in the header, when generating PostScript."
2295 :type 'symbol
2296 :group 'ps-print-font)
2298 (defcustom ps-header-font-size '(10 . 12)
2299 "*Font size, in points, for text in the header, when generating PostScript."
2300 :type '(choice (number :tag "Header Size")
2301 (cons :tag "Landscape/Portrait"
2302 (number :tag "Landscape Header Size")
2303 (number :tag "Portrait Header Size")))
2304 :group 'ps-print-font)
2306 (defcustom ps-header-title-font-size '(12 . 14)
2307 "*Font size, in points, for the top line of text in header, in PostScript."
2308 :type '(choice (number :tag "Header Title Size")
2309 (cons :tag "Landscape/Portrait"
2310 (number :tag "Landscape Header Title Size")
2311 (number :tag "Portrait Header Title Size")))
2312 :group 'ps-print-font)
2314 ;;; Colors
2316 ;; Printing color requires x-color-values.
2317 (defcustom ps-print-color-p (or (fboundp 'x-color-values) ; Emacs
2318 (fboundp 'color-instance-rgb-components))
2319 ; XEmacs
2320 "*Non-nil means print the buffer's text in color."
2321 :type 'boolean
2322 :group 'ps-print-color)
2324 (defcustom ps-default-fg '(0.0 0.0 0.0)
2325 "*RGB values of the default foreground color. Defaults to black."
2326 :type '(choice :menu-tag "Default Foreground Gray/Color"
2327 :tag "Default Foreground Gray/Color"
2328 (number :tag "Gray Scale" :value 0.0)
2329 (string :tag "Color Name" :value "black")
2330 (list :tag "RGB Color" :value (0.0 0.0 0.0)
2331 (number :tag "Red")
2332 (number :tag "Green")
2333 (number :tag "Blue")))
2334 :group 'ps-print-color)
2336 (defcustom ps-default-bg '(1.0 1.0 1.0)
2337 "*RGB values of the default background color. Defaults to white."
2338 :type '(choice :menu-tag "Default Background Gray/Color"
2339 :tag "Default Background Gray/Color"
2340 (number :tag "Gray Scale" :value 1.0)
2341 (string :tag "Color Name" :value "white")
2342 (list :tag "RGB Color" :value (1.0 1.0 1.0)
2343 (number :tag "Red")
2344 (number :tag "Green")
2345 (number :tag "Blue")))
2346 :group 'ps-print-color)
2348 (defcustom ps-auto-font-detect t
2349 "*Non-nil means automatically detect bold/italic face attributes.
2350 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
2351 and `ps-underlined-faces'."
2352 :type 'boolean
2353 :group 'ps-print-font)
2355 (defcustom ps-bold-faces
2356 (unless ps-print-color-p
2357 '(font-lock-function-name-face
2358 font-lock-builtin-face
2359 font-lock-variable-name-face
2360 font-lock-keyword-face
2361 font-lock-warning-face))
2362 "*A list of the \(non-bold\) faces that should be printed in bold font.
2363 This applies to generating PostScript."
2364 :type '(repeat face)
2365 :group 'ps-print-face)
2367 (defcustom ps-italic-faces
2368 (unless ps-print-color-p
2369 '(font-lock-variable-name-face
2370 font-lock-type-face
2371 font-lock-string-face
2372 font-lock-comment-face
2373 font-lock-warning-face))
2374 "*A list of the \(non-italic\) faces that should be printed in italic font.
2375 This applies to generating PostScript."
2376 :type '(repeat face)
2377 :group 'ps-print-face)
2379 (defcustom ps-underlined-faces
2380 (unless ps-print-color-p
2381 '(font-lock-function-name-face
2382 font-lock-constant-face
2383 font-lock-warning-face))
2384 "*A list of the \(non-underlined\) faces that should be printed underlined.
2385 This applies to generating PostScript."
2386 :type '(repeat face)
2387 :group 'ps-print-face)
2389 (defcustom ps-use-face-background nil
2390 "*Specify if face background should be used.
2392 Valid values are:
2394 t always use face background color.
2395 nil never use face background color.
2396 (face...) list of faces whose background color will be used.
2398 Any other value will be treated as t."
2399 :type '(choice :menu-tag "Use Face Background"
2400 :tag "Use Face Background"
2401 (const :tag "Always Use Face Background" t)
2402 (const :tag "Never Use Face Background" nil)
2403 (repeat :menu-tag "Face Background List"
2404 :tag "Face Background List"
2405 face))
2406 :group 'ps-print-face)
2408 (defcustom ps-left-header
2409 (list 'ps-get-buffer-name 'ps-header-dirpart)
2410 "*The items to display (each on a line) on the left part of the page header.
2411 This applies to generating PostScript.
2413 The value should be a list of strings and symbols, each representing an
2414 entry in the PostScript array HeaderLinesLeft.
2416 Strings are inserted unchanged into the array; those representing
2417 PostScript string literals should be delimited with PostScript string
2418 delimiters '(' and ')'.
2420 For symbols with bound functions, the function is called and should
2421 return a string to be inserted into the array. For symbols with bound
2422 values, the value should be a string to be inserted into the array.
2423 In either case, function or variable, the string value has PostScript
2424 string delimiters added to it."
2425 :type '(repeat (choice string symbol))
2426 :group 'ps-print-headers)
2428 (defcustom ps-right-header
2429 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss)
2430 "*The items to display (each on a line) on the right part of the page header.
2431 This applies to generating PostScript.
2433 See the variable `ps-left-header' for a description of the format of
2434 this variable."
2435 :type '(repeat (choice string symbol))
2436 :group 'ps-print-headers)
2438 (defcustom ps-razzle-dazzle t
2439 "*Non-nil means report progress while formatting buffer."
2440 :type 'boolean
2441 :group 'ps-print-miscellany)
2443 (defcustom ps-adobe-tag "%!PS-Adobe-3.0\n"
2444 "*Contains the header line identifying the output as PostScript.
2445 By default, `ps-adobe-tag' contains the standard identifier. Some
2446 printers require slightly different versions of this line."
2447 :type 'string
2448 :group 'ps-print-miscellany)
2450 (defcustom ps-build-face-reference t
2451 "*Non-nil means build the reference face lists.
2453 ps-print sets this value to nil after it builds its internal reference
2454 lists of bold and italic faces. By settings its value back to t, you
2455 can force ps-print to rebuild the lists the next time you invoke one
2456 of the ...-with-faces commands.
2458 You should set this value back to t after you change the attributes of
2459 any face, or create new faces. Most users shouldn't have to worry
2460 about its setting, though."
2461 :type 'boolean
2462 :group 'ps-print-face)
2464 (defcustom ps-always-build-face-reference nil
2465 "*Non-nil means always rebuild the reference face lists.
2467 If this variable is non-nil, ps-print will rebuild its internal
2468 reference lists of bold and italic faces *every* time one of the
2469 ...-with-faces commands is called. Most users shouldn't need to set this
2470 variable."
2471 :type 'boolean
2472 :group 'ps-print-face)
2474 (defcustom ps-banner-page-when-duplexing nil
2475 "*Non-nil means the very first page is skipped.
2476 It's like the very first character of buffer (or region) is ^L (\\014)."
2477 :type 'boolean
2478 :group 'ps-print-headers)
2480 (defcustom ps-postscript-code-directory
2481 (or (and (fboundp 'locate-data-directory) ; xemacs
2482 (locate-data-directory "ps-print"))
2483 data-directory) ; emacs
2484 "*Directory where it's located the PostScript prologue file used by ps-print.
2485 By default, this directory is the same as in the variable `data-directory'."
2486 :type 'directory
2487 :group 'ps-print-miscellany)
2490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2491 ;; Selected Pages
2494 (defvar ps-last-selected-pages nil
2495 "Latest `ps-selected-pages' value.")
2498 (defun ps-restore-selected-pages ()
2499 "Restore latest `ps-selected-pages' value."
2500 (interactive)
2501 (setq ps-selected-pages ps-last-selected-pages))
2504 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2505 ;; Customization
2508 ;;;###autoload
2509 (defun ps-print-customize ()
2510 "Customization of ps-print group."
2511 (interactive)
2512 (customize-group 'ps-print))
2515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2516 ;; User commands
2519 ;;;###autoload
2520 (defun ps-print-buffer (&optional filename)
2521 "Generate and print a PostScript image of the buffer.
2523 Interactively, when you use a prefix argument (C-u), the command
2524 prompts the user for a file name, and saves the PostScript image
2525 in that file instead of sending it to the printer.
2527 Noninteractively, the argument FILENAME is treated as follows: if it
2528 is nil, send the image to the printer. If FILENAME is a string, save
2529 the PostScript image in a file with that name."
2530 (interactive (list (ps-print-preprint current-prefix-arg)))
2531 (ps-print-without-faces (point-min) (point-max) filename))
2534 ;;;###autoload
2535 (defun ps-print-buffer-with-faces (&optional filename)
2536 "Generate and print a PostScript image of the buffer.
2537 Like `ps-print-buffer', but includes font, color, and underline
2538 information in the generated image. This command works only if you
2539 are using a window system, so it has a way to determine color values."
2540 (interactive (list (ps-print-preprint current-prefix-arg)))
2541 (ps-print-with-faces (point-min) (point-max) filename))
2544 ;;;###autoload
2545 (defun ps-print-region (from to &optional filename)
2546 "Generate and print a PostScript image of the region.
2547 Like `ps-print-buffer', but prints just the current region."
2548 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
2549 (ps-print-without-faces from to filename t))
2552 ;;;###autoload
2553 (defun ps-print-region-with-faces (from to &optional filename)
2554 "Generate and print a PostScript image of the region.
2555 Like `ps-print-region', but includes font, color, and underline
2556 information in the generated image. This command works only if you
2557 are using a window system, so it has a way to determine color values."
2558 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
2559 (ps-print-with-faces from to filename t))
2562 ;;;###autoload
2563 (defun ps-spool-buffer ()
2564 "Generate and spool a PostScript image of the buffer.
2565 Like `ps-print-buffer' except that the PostScript image is saved in a
2566 local buffer to be sent to the printer later.
2568 Use the command `ps-despool' to send the spooled images to the printer."
2569 (interactive)
2570 (ps-spool-without-faces (point-min) (point-max)))
2573 ;;;###autoload
2574 (defun ps-spool-buffer-with-faces ()
2575 "Generate and spool a PostScript image of the buffer.
2576 Like `ps-spool-buffer', but includes font, color, and underline
2577 information in the generated image. This command works only if you
2578 are using a window system, so it has a way to determine color values.
2580 Use the command `ps-despool' to send the spooled images to the printer."
2581 (interactive)
2582 (ps-spool-with-faces (point-min) (point-max)))
2585 ;;;###autoload
2586 (defun ps-spool-region (from to)
2587 "Generate a PostScript image of the region and spool locally.
2588 Like `ps-spool-buffer', but spools just the current region.
2590 Use the command `ps-despool' to send the spooled images to the printer."
2591 (interactive "r")
2592 (ps-spool-without-faces from to t))
2595 ;;;###autoload
2596 (defun ps-spool-region-with-faces (from to)
2597 "Generate a PostScript image of the region and spool locally.
2598 Like `ps-spool-region', but includes font, color, and underline
2599 information in the generated image. This command works only if you
2600 are using a window system, so it has a way to determine color values.
2602 Use the command `ps-despool' to send the spooled images to the printer."
2603 (interactive "r")
2604 (ps-spool-with-faces from to t))
2606 ;;;###autoload
2607 (defun ps-despool (&optional filename)
2608 "Send the spooled PostScript to the printer.
2610 Interactively, when you use a prefix argument (C-u), the command
2611 prompts the user for a file name, and saves the spooled PostScript
2612 image in that file instead of sending it to the printer.
2614 Noninteractively, the argument FILENAME is treated as follows: if it
2615 is nil, send the image to the printer. If FILENAME is a string, save
2616 the PostScript image in a file with that name."
2617 (interactive (list (ps-print-preprint current-prefix-arg)))
2618 (ps-do-despool filename))
2620 ;;;###autoload
2621 (defun ps-line-lengths ()
2622 "Display the correspondence between a line length and a font size,
2623 using the current ps-print setup.
2624 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2625 (interactive)
2626 (ps-line-lengths-internal))
2628 ;;;###autoload
2629 (defun ps-nb-pages-buffer (nb-lines)
2630 "Display number of pages to print this buffer, for various font heights.
2631 The table depends on the current ps-print setup."
2632 (interactive (list (count-lines (point-min) (point-max))))
2633 (ps-nb-pages nb-lines))
2635 ;;;###autoload
2636 (defun ps-nb-pages-region (nb-lines)
2637 "Display number of pages to print the region, for various font heights.
2638 The table depends on the current ps-print setup."
2639 (interactive (list (count-lines (mark) (point))))
2640 (ps-nb-pages nb-lines))
2642 ;;;###autoload
2643 (defun ps-setup ()
2644 "Return the current PostScript-generation setup."
2645 (format
2647 ;;; ps-print version %s
2649 \(setq ps-print-color-p %s
2650 ps-lpr-command %S
2651 ps-lpr-switches %s
2652 ps-printer-name %S
2653 ps-print-region-function %s
2654 ps-manual-feed %S
2656 ps-paper-type %s
2657 ps-warn-paper-type %s
2658 ps-landscape-mode %s
2659 ps-print-upside-down %s
2660 ps-number-of-columns %s
2662 ps-zebra-stripes %s
2663 ps-zebra-stripe-height %s
2664 ps-zebra-stripe-follow %S
2665 ps-zebra-color %s
2666 ps-line-number %s
2667 ps-line-number-step %s
2668 ps-line-number-start %S
2670 ps-default-fg %s
2671 ps-default-bg %s
2673 ps-use-face-background %s
2675 ps-print-control-characters %s
2677 ps-print-background-image %s
2679 ps-print-background-text %s
2681 ps-error-handler-message %s
2682 ps-user-defined-prologue %s
2683 ps-print-prologue-header %s
2685 ps-left-margin %s
2686 ps-right-margin %s
2687 ps-inter-column %s
2688 ps-bottom-margin %s
2689 ps-top-margin %s
2690 ps-header-offset %s
2691 ps-header-line-pad %s
2692 ps-print-header %s
2693 ps-print-only-one-header %s
2694 ps-print-header-frame %s
2695 ps-switch-header %s
2696 ps-header-lines %s
2697 ps-show-n-of-n %s
2698 ps-spool-config %s
2699 ps-spool-duplex %s
2700 ps-spool-tumble %s
2701 ps-banner-page-when-duplexing %s
2703 ps-n-up-printing %s
2704 ps-n-up-margin %s
2705 ps-n-up-border-p %s
2706 ps-n-up-filling %s
2708 ps-multibyte-buffer %s
2709 ps-font-family %s
2710 ps-font-size %s
2711 ps-header-font-family %s
2712 ps-header-font-size %s
2713 ps-header-title-font-size %s
2715 ps-selected-pages %s
2716 ps-last-selected-pages %s)
2718 ;;; ps-print - end of settings
2720 ps-print-version
2721 ps-print-color-p
2722 ps-lpr-command
2723 (ps-print-quote ps-lpr-switches)
2724 ps-printer-name
2725 (ps-print-quote ps-print-region-function)
2726 ps-manual-feed
2727 (ps-print-quote ps-paper-type)
2728 ps-warn-paper-type
2729 ps-landscape-mode
2730 ps-print-upside-down
2731 ps-number-of-columns
2732 ps-zebra-stripes
2733 ps-zebra-stripe-height
2734 ps-zebra-stripe-follow
2735 (ps-print-quote ps-zebra-color)
2736 ps-line-number
2737 (ps-print-quote ps-line-number-step)
2738 ps-line-number-start
2739 (ps-print-quote ps-default-fg)
2740 (ps-print-quote ps-default-bg)
2741 (ps-print-quote ps-use-face-background)
2742 (ps-print-quote ps-print-control-characters)
2743 (ps-print-quote ps-print-background-image)
2744 (ps-print-quote ps-print-background-text)
2745 (ps-print-quote ps-error-handler-message)
2746 (ps-print-quote ps-user-defined-prologue)
2747 (ps-print-quote ps-print-prologue-header)
2748 ps-left-margin
2749 ps-right-margin
2750 ps-inter-column
2751 ps-bottom-margin
2752 ps-top-margin
2753 ps-header-offset
2754 ps-header-line-pad
2755 ps-print-header
2756 ps-print-only-one-header
2757 ps-print-header-frame
2758 (ps-print-quote ps-switch-header)
2759 ps-header-lines
2760 ps-show-n-of-n
2761 (ps-print-quote ps-spool-config)
2762 ps-spool-duplex
2763 ps-spool-tumble
2764 ps-banner-page-when-duplexing
2765 ps-n-up-printing
2766 ps-n-up-margin
2767 ps-n-up-border-p
2768 (ps-print-quote ps-n-up-filling)
2769 (ps-print-quote ps-multibyte-buffer) ; see `ps-mule.el'
2770 (ps-print-quote ps-font-family)
2771 (ps-print-quote ps-font-size)
2772 (ps-print-quote ps-header-font-family)
2773 (ps-print-quote ps-header-font-size)
2774 (ps-print-quote ps-header-title-font-size)
2775 (ps-print-quote ps-selected-pages)
2776 (ps-print-quote ps-last-selected-pages)))
2779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2780 ;; Utility functions and variables:
2783 (defun ps-print-quote (sym)
2784 (cond ((null sym)
2785 nil)
2786 ((or (symbolp sym) (listp sym))
2787 (format "'%S" sym))
2788 ((stringp sym)
2789 (format "%S" sym))
2791 sym)))
2793 (defvar ps-print-emacs-type
2794 (cond ((string-match "XEmacs" emacs-version) 'xemacs)
2795 ((string-match "Lucid" emacs-version) 'lucid)
2796 ((string-match "Epoch" emacs-version) 'epoch)
2797 (t 'emacs)))
2799 (if (memq ps-print-emacs-type '(lucid xemacs))
2800 (if (< emacs-minor-version 12)
2801 (setq ps-print-color-p nil))
2802 (require 'faces)) ; face-font, face-underline-p,
2803 ; x-font-regexp
2805 ;; Return t if the device (which can be changed during an emacs session)
2806 ;; can handle colors.
2807 ;; This is function is not yet implemented for GNU emacs.
2808 (cond ((and (eq ps-print-emacs-type 'xemacs)
2809 (>= emacs-minor-version 12)) ; xemacs
2810 (defun ps-color-device ()
2811 (eq (device-class) 'color))
2814 (t ; emacs
2815 (defun ps-color-device ()
2820 (require 'time-stamp)
2823 (defun ps-prologue-file (filenumber)
2824 (save-excursion
2825 (let* ((filename (format "%sps-prin%d.ps"
2826 ps-postscript-code-directory filenumber))
2827 (buffer
2828 (or (find-file-noselect filename 'no-warn 'rawfile)
2829 (error "ps-print PostScript prologue `%s' file was not found."
2830 filename))))
2831 (set-buffer buffer)
2832 (prog1
2833 (buffer-string)
2834 (kill-buffer buffer)))))
2837 (defvar ps-mark-code-directory nil)
2839 (defvar ps-print-prologue-0 ""
2840 "ps-print PostScript error handler.")
2842 (defvar ps-print-prologue-1 ""
2843 "ps-print PostScript prologue begin.")
2845 (defvar ps-print-prologue-2 ""
2846 "ps-print PostScript prologue end.")
2848 (defvar ps-print-duplex-feature ""
2849 "ps-print PostScript duplex feature.")
2851 ;; Start Editing Here:
2853 (defvar ps-source-buffer nil)
2854 (defvar ps-spool-buffer-name "*PostScript*")
2855 (defvar ps-spool-buffer nil)
2857 (defvar ps-output-head nil)
2858 (defvar ps-output-tail nil)
2860 (defvar ps-page-postscript 0)
2861 (defvar ps-page-order 0)
2862 (defvar ps-page-count 0)
2863 (defvar ps-showline-count 1)
2864 (defvar ps-first-page nil)
2865 (defvar ps-last-page nil)
2867 (defvar ps-control-or-escape-regexp nil)
2868 (defvar ps-n-up-on nil)
2870 (defvar ps-background-pages nil)
2871 (defvar ps-background-all-pages nil)
2872 (defvar ps-background-text-count 0)
2873 (defvar ps-background-image-count 0)
2875 (defvar ps-current-font 0)
2876 (defvar ps-default-foreground nil)
2877 (defvar ps-default-color nil)
2878 (defvar ps-current-color nil)
2879 (defvar ps-current-bg nil)
2881 (defvar ps-razchunk 0)
2883 (defvar ps-color-p nil)
2884 (defvar ps-color-format
2885 (if (eq ps-print-emacs-type 'emacs)
2887 ;; Emacs understands the %f format; we'll use it to limit color RGB
2888 ;; values to three decimals to cut down some on the size of the
2889 ;; PostScript output.
2890 "%0.3f %0.3f %0.3f"
2892 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2893 "%s %s %s"))
2895 ;; These values determine how much print-height to deduct when headers
2896 ;; are turned on. This is a pretty clumsy way of handling it, but
2897 ;; it'll do for now.
2899 (defvar ps-header-pad 0
2900 "Vertical and horizontal space between the header frame and the text.
2901 This is in units of points (1/72 inch).")
2903 ;; Define accessors to the dimensions list.
2905 (defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims))
2906 (defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
2907 (defmacro ps-page-dimensions-get-media (dims) `(nth 2 ,dims))
2909 (defvar ps-landscape-page-height nil)
2911 (defvar ps-print-width nil)
2912 (defvar ps-print-height nil)
2914 (defvar ps-height-remaining nil)
2915 (defvar ps-width-remaining nil)
2917 (defvar ps-print-color-scale nil)
2919 (defvar ps-font-size-internal nil)
2920 (defvar ps-header-font-size-internal nil)
2921 (defvar ps-header-title-font-size-internal nil)
2924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2925 ;; Internal Variables
2928 (defvar ps-print-face-extension-alist nil
2929 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2930 An element of this list has the following form:
2932 (FACE . [BITS FG BG])
2934 FACE is a symbol denoting a face name
2935 BITS is a bit vector, where each bit correspond
2936 to a feature (bold, underline, etc)
2937 (see documentation for `ps-print-face-map-alist')
2938 FG foreground color (string or nil)
2939 BG background color (string or nil)
2941 Don't change this list directly; instead,
2942 use `ps-extend-face' and `ps-extend-face-list'.
2943 See documentation for `ps-extend-face' for valid extension symbol.")
2946 (defvar ps-print-face-alist nil
2947 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2949 An element of this list has the same form as an element of
2950 `ps-print-face-extension-alist'.
2952 Don't change this list directly; this list is used by `ps-face-attributes',
2953 `ps-map-face' and `ps-build-reference-face-lists'.")
2956 (defconst ps-print-face-map-alist
2957 '((bold . 1)
2958 (italic . 2)
2959 (underline . 4)
2960 (strikeout . 8)
2961 (overline . 16)
2962 (shadow . 32)
2963 (box . 64)
2964 (outline . 128))
2965 "Alist of all features and the corresponding bit mask.
2966 Each symbol correspond to one bit in a bit vector.")
2969 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2970 ;; Remapping Faces
2973 ;;;###autoload
2974 (defun ps-extend-face-list (face-extension-list &optional merge-p)
2975 "Extend face in `ps-print-face-extension-alist'.
2977 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2978 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2980 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2982 See `ps-extend-face' for documentation."
2983 (while face-extension-list
2984 (ps-extend-face (car face-extension-list) merge-p)
2985 (setq face-extension-list (cdr face-extension-list))))
2988 ;;;###autoload
2989 (defun ps-extend-face (face-extension &optional merge-p)
2990 "Extend face in `ps-print-face-extension-alist'.
2992 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2993 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2995 The elements of FACE-EXTENSION list have the form:
2997 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2999 FACE-NAME is a face name symbol.
3001 FOREGROUND and BACKGROUND may be nil or a string that denotes the
3002 foreground and background colors respectively.
3004 EXTENSION is one of the following symbols:
3005 bold - use bold font.
3006 italic - use italic font.
3007 underline - put a line under text.
3008 strikeout - like underline, but the line is in middle of text.
3009 overline - like underline, but the line is over the text.
3010 shadow - text will have a shadow.
3011 box - text will be surrounded by a box.
3012 outline - print characters as hollow outlines.
3014 If EXTENSION is any other symbol, it is ignored."
3015 (let* ((face-name (nth 0 face-extension))
3016 (foreground (nth 1 face-extension))
3017 (background (nth 2 face-extension))
3018 (ps-face (cdr (assq face-name ps-print-face-extension-alist)))
3019 (face-vector (or ps-face (vector 0 nil nil)))
3020 (face-bit (ps-extension-bit face-extension)))
3021 ;; extend face
3022 (aset face-vector 0 (if merge-p
3023 (logior (aref face-vector 0) face-bit)
3024 face-bit))
3025 (and foreground (stringp foreground) (aset face-vector 1 foreground))
3026 (and background (stringp background) (aset face-vector 2 background))
3027 ;; if face does not exist, insert it
3028 (or ps-face
3029 (setq ps-print-face-extension-alist
3030 (cons (cons face-name face-vector)
3031 ps-print-face-extension-alist)))))
3034 (defun ps-extension-bit (face-extension)
3035 (let ((face-bit 0))
3036 ;; map valid symbol extension to bit vector
3037 (setq face-extension (cdr (cdr face-extension)))
3038 (while (setq face-extension (cdr face-extension))
3039 (setq face-bit (logior face-bit
3040 (or (cdr (assq (car face-extension)
3041 ps-print-face-map-alist))
3042 0))))
3043 face-bit))
3046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3047 ;; Adapted from font-lock: (obsolete stuff)
3048 ;; Originally face attributes were specified via `font-lock-face-attributes'.
3049 ;; Users then changed the default face attributes by setting that variable.
3050 ;; However, we try and be back-compatible and respect its value if set except
3051 ;; for faces where M-x customize has been used to save changes for the face.
3054 (defun ps-font-lock-face-attributes ()
3055 (and (boundp 'font-lock-mode) (symbol-value 'font-lock-mode)
3056 (boundp 'font-lock-face-attributes)
3057 (let ((face-attributes font-lock-face-attributes))
3058 (while face-attributes
3059 (let* ((face-attribute
3060 (car (prog1 face-attributes
3061 (setq face-attributes (cdr face-attributes)))))
3062 (face (car face-attribute)))
3063 ;; Rustle up a `defface' SPEC from a
3064 ;; `font-lock-face-attributes' entry.
3065 (unless (get face 'saved-face)
3066 (let ((foreground (nth 1 face-attribute))
3067 (background (nth 2 face-attribute))
3068 (bold-p (nth 3 face-attribute))
3069 (italic-p (nth 4 face-attribute))
3070 (underline-p (nth 5 face-attribute))
3071 face-spec)
3072 (when foreground
3073 (setq face-spec (cons ':foreground
3074 (cons foreground face-spec))))
3075 (when background
3076 (setq face-spec (cons ':background
3077 (cons background face-spec))))
3078 (when bold-p
3079 (setq face-spec (append '(:bold t) face-spec)))
3080 (when italic-p
3081 (setq face-spec (append '(:italic t) face-spec)))
3082 (when underline-p
3083 (setq face-spec (append '(:underline t) face-spec)))
3084 (custom-declare-face face (list (list t face-spec)) nil)
3085 )))))))
3088 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3089 ;; Internal functions and variables
3092 (make-local-hook 'ps-print-hook)
3093 (make-local-hook 'ps-print-begin-sheet-hook)
3094 (make-local-hook 'ps-print-begin-page-hook)
3095 (make-local-hook 'ps-print-begin-column-hook)
3098 (defun ps-print-without-faces (from to &optional filename region-p)
3099 (ps-spool-without-faces from to region-p)
3100 (ps-do-despool filename))
3103 (defun ps-spool-without-faces (from to &optional region-p)
3104 (run-hooks 'ps-print-hook)
3105 (ps-printing-region region-p from)
3106 (ps-generate (current-buffer) from to 'ps-generate-postscript))
3109 (defun ps-print-with-faces (from to &optional filename region-p)
3110 (ps-spool-with-faces from to region-p)
3111 (ps-do-despool filename))
3114 (defun ps-spool-with-faces (from to &optional region-p)
3115 (run-hooks 'ps-print-hook)
3116 (ps-printing-region region-p from)
3117 (ps-generate (current-buffer) from to 'ps-generate-postscript-with-faces))
3120 (defun ps-count-lines (from to)
3121 (+ (count-lines from to)
3122 (save-excursion
3123 (goto-char to)
3124 (if (= (current-column) 0) 1 0))))
3127 (defvar ps-printing-region nil
3128 "Variable used to indicate if the region that ps-print is printing.
3129 It is a cons, the car of which is the line number where the region begins, and
3130 its cdr is the total number of lines in the buffer. Formatting functions can
3131 use this information to print the original line number (and not the number of
3132 lines printed), and to indicate in the header that the printout is of a partial
3133 file.")
3136 (defvar ps-printing-region-p nil
3137 "Non-nil means ps-print is printing a region.")
3140 (defun ps-printing-region (region-p from)
3141 (setq ps-printing-region-p region-p
3142 ps-printing-region
3143 (cons (if region-p
3144 (ps-count-lines (point-min) from)
3146 (ps-count-lines (point-min) (point-max)))))
3149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3150 ;; Internal functions
3153 (defsubst ps-font-alist (font-sym)
3154 (get font-sym 'fonts))
3156 (defun ps-font (font-sym font-type)
3157 "Font family name for text of `font-type', when generating PostScript."
3158 (let* ((font-list (ps-font-alist font-sym))
3159 (normal-font (cdr (assq 'normal font-list))))
3160 (while (and font-list (not (eq font-type (car (car font-list)))))
3161 (setq font-list (cdr font-list)))
3162 (or (cdr (car font-list)) normal-font)))
3164 (defun ps-fonts (font-sym)
3165 (mapcar 'cdr (ps-font-alist font-sym)))
3167 (defun ps-font-number (font-sym font-type)
3168 (or (ps-alist-position font-type (ps-font-alist font-sym))
3171 (defsubst ps-line-height (font-sym)
3172 "The height of a line, for generating PostScript.
3173 This is the value that ps-print uses to determine the height,
3174 y-dimension, of the lines of text it has printed, and thus affects the
3175 point at which page-breaks are placed.
3176 The line-height is *not* the same as the point size of the font."
3177 (get font-sym 'line-height))
3179 (defsubst ps-title-line-height (font-sym)
3180 "The height of a `title' line, for generating PostScript.
3181 This is the value that ps-print uses to determine the height,
3182 y-dimension, of the lines of text it has printed, and thus affects the
3183 point at which page-breaks are placed.
3184 The title-line-height is *not* the same as the point size of the font."
3185 (get font-sym 'title-line-height))
3187 (defsubst ps-space-width (font-sym)
3188 "The width of a space character, for generating PostScript.
3189 This value is used in expanding tab characters."
3190 (get font-sym 'space-width))
3192 (defsubst ps-avg-char-width (font-sym)
3193 "The average width, in points, of a character, for generating PostScript.
3194 This is the value that ps-print uses to determine the length,
3195 x-dimension, of the text it has printed, and thus affects the point at
3196 which long lines wrap around."
3197 (get font-sym 'avg-char-width))
3199 (defun ps-line-lengths-internal ()
3200 "Display the correspondence between a line length and a font size,
3201 using the current ps-print setup.
3202 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
3203 (let ((buf (get-buffer-create "*Line-lengths*"))
3204 (ifs ps-font-size-internal) ; initial font size
3205 (icw (ps-avg-char-width 'ps-font-for-text)) ; initial character width
3206 (print-width (progn (ps-get-page-dimensions)
3207 ps-print-width))
3208 (ps-setup (ps-setup)) ; setup for the current buffer
3209 (fs-min 5) ; minimum font size
3210 cw-min ; minimum character width
3211 nb-cpl-max ; maximum nb of characters per line
3212 (fs-max 14) ; maximum font size
3213 cw-max ; maximum character width
3214 nb-cpl-min ; minimum nb of characters per line
3215 fs ; current font size
3216 cw ; current character width
3217 nb-cpl ; current nb of characters per line
3219 (setq cw-min (/ (* icw fs-min) ifs)
3220 nb-cpl-max (floor (/ print-width cw-min))
3221 cw-max (/ (* icw fs-max) ifs)
3222 nb-cpl-min (floor (/ print-width cw-max))
3223 nb-cpl nb-cpl-min)
3224 (set-buffer buf)
3225 (goto-char (point-max))
3226 (or (bolp) (insert "\n"))
3227 (insert ps-setup
3228 "nb char per line / font size\n")
3229 (while (<= nb-cpl nb-cpl-max)
3230 (setq cw (/ print-width (float nb-cpl))
3231 fs (/ (* ifs cw) icw))
3232 (insert (format "%3s %s\n" nb-cpl fs))
3233 (setq nb-cpl (1+ nb-cpl)))
3234 (insert "\n")
3235 (display-buffer buf 'not-this-window)))
3237 (defun ps-nb-pages (nb-lines)
3238 "Display correspondence between font size and the number of pages.
3239 The correspondence is based on having NB-LINES lines of text,
3240 and on the current ps-print setup."
3241 (let ((buf (get-buffer-create "*Nb-Pages*"))
3242 (ifs ps-font-size-internal) ; initial font size
3243 (ilh (ps-line-height 'ps-font-for-text)) ; initial line height
3244 (page-height (progn (ps-get-page-dimensions)
3245 ps-print-height))
3246 (ps-setup (ps-setup)) ; setup for the current buffer
3247 (fs-min 4) ; minimum font size
3248 lh-min ; minimum line height
3249 nb-lpp-max ; maximum nb of lines per page
3250 nb-page-min ; minimum nb of pages
3251 (fs-max 14) ; maximum font size
3252 lh-max ; maximum line height
3253 nb-lpp-min ; minimum nb of lines per page
3254 nb-page-max ; maximum nb of pages
3255 fs ; current font size
3256 lh ; current line height
3257 nb-lpp ; current nb of lines per page
3258 nb-page ; current nb of pages
3260 (setq lh-min (/ (* ilh fs-min) ifs)
3261 nb-lpp-max (floor (/ page-height lh-min))
3262 nb-page-min (ceiling (/ (float nb-lines) nb-lpp-max))
3263 lh-max (/ (* ilh fs-max) ifs)
3264 nb-lpp-min (floor (/ page-height lh-max))
3265 nb-page-max (ceiling (/ (float nb-lines) nb-lpp-min))
3266 nb-page nb-page-min)
3267 (set-buffer buf)
3268 (goto-char (point-max))
3269 (or (bolp) (insert "\n"))
3270 (insert ps-setup
3271 (format "%d lines\n" nb-lines)
3272 "nb page / font size\n")
3273 (while (<= nb-page nb-page-max)
3274 (setq nb-lpp (ceiling (/ nb-lines (float nb-page)))
3275 lh (/ page-height nb-lpp)
3276 fs (/ (* ifs lh) ilh))
3277 (insert (format "%s %s\n" nb-page fs))
3278 (setq nb-page (1+ nb-page)))
3279 (insert "\n")
3280 (display-buffer buf 'not-this-window)))
3282 ;; macros used in `ps-select-font'
3283 (defmacro ps-lookup (key) `(cdr (assq ,key font-entry)))
3284 (defmacro ps-size-scale (key) `(/ (* (ps-lookup ,key) font-size) size))
3286 (defun ps-select-font (font-family sym font-size title-font-size)
3287 (let ((font-entry (cdr (assq font-family ps-font-info-database))))
3288 (or font-entry
3289 (error "Don't have data to scale font %s. Known fonts families are %s"
3290 font-family
3291 (mapcar 'car ps-font-info-database)))
3292 (let ((size (ps-lookup 'size)))
3293 (put sym 'fonts (ps-lookup 'fonts))
3294 (put sym 'space-width (ps-size-scale 'space-width))
3295 (put sym 'avg-char-width (ps-size-scale 'avg-char-width))
3296 (put sym 'line-height (ps-size-scale 'line-height))
3297 (put sym 'title-line-height
3298 (/ (* (ps-lookup 'line-height) title-font-size) size)))))
3300 (defun ps-get-page-dimensions ()
3301 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
3302 page-width page-height)
3303 (cond
3304 ((null page-dimensions)
3305 (error "`ps-paper-type' must be one of:\n%s"
3306 (mapcar 'car ps-page-dimensions-database)))
3307 ((< ps-number-of-columns 1)
3308 (error "The number of columns %d should be positive"
3309 ps-number-of-columns)))
3311 (ps-select-font ps-font-family 'ps-font-for-text
3312 ps-font-size-internal ps-font-size-internal)
3313 (ps-select-font ps-header-font-family 'ps-font-for-header
3314 ps-header-font-size-internal
3315 ps-header-title-font-size-internal)
3317 (setq page-width (ps-page-dimensions-get-width page-dimensions)
3318 page-height (ps-page-dimensions-get-height page-dimensions))
3320 ;; Landscape mode
3321 (if ps-landscape-mode
3322 ;; exchange width and height
3323 (setq page-width (prog1 page-height (setq page-height page-width))))
3325 ;; It is used to get the lower right corner (only in landscape mode)
3326 (setq ps-landscape-page-height page-height)
3328 ;; | lm | text | ic | text | ic | text | rm |
3329 ;; page-width == lm + n * pw + (n - 1) * ic + rm
3330 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
3331 (setq ps-print-width (/ (- page-width
3332 ps-left-margin ps-right-margin
3333 (* (1- ps-number-of-columns) ps-inter-column))
3334 ps-number-of-columns))
3335 (if (<= ps-print-width 0)
3336 (error "Bad horizontal layout:
3337 page-width == %s
3338 ps-left-margin == %s
3339 ps-right-margin == %s
3340 ps-inter-column == %s
3341 ps-number-of-columns == %s
3342 | lm | text | ic | text | ic | text | rm |
3343 page-width == lm + n * print-width + (n - 1) * ic + rm
3344 => print-width == %d !"
3345 page-width
3346 ps-left-margin
3347 ps-right-margin
3348 ps-inter-column
3349 ps-number-of-columns
3350 ps-print-width))
3352 (setq ps-print-height
3353 (- page-height ps-bottom-margin ps-top-margin))
3354 (if (<= ps-print-height 0)
3355 (error "Bad vertical layout:
3356 ps-top-margin == %s
3357 ps-bottom-margin == %s
3358 page-height == bm + print-height + tm
3359 => print-height == %d !"
3360 ps-top-margin
3361 ps-bottom-margin
3362 ps-print-height))
3363 ;; If headers are turned on, deduct the height of the header from
3364 ;; the print height.
3365 (if ps-print-header
3366 (setq ps-header-pad (* ps-header-line-pad
3367 (ps-title-line-height 'ps-font-for-header))
3368 ps-print-height (- ps-print-height
3369 ps-header-offset
3370 ps-header-pad
3371 (ps-title-line-height 'ps-font-for-header)
3372 (* (ps-line-height 'ps-font-for-header)
3373 (1- ps-header-lines))
3374 ps-header-pad)))
3375 (if (<= ps-print-height 0)
3376 (error "Bad vertical layout:
3377 ps-top-margin == %s
3378 ps-bottom-margin == %s
3379 ps-header-offset == %s
3380 ps-header-pad == %s
3381 header-height == %s
3382 page-height == bm + print-height + tm - ho - hh
3383 => print-height == %d !"
3384 ps-top-margin
3385 ps-bottom-margin
3386 ps-header-offset
3387 ps-header-pad
3388 (+ ps-header-pad
3389 (ps-title-line-height 'ps-font-for-header)
3390 (* (ps-line-height 'ps-font-for-header)
3391 (1- ps-header-lines))
3392 ps-header-pad)
3393 ps-print-height))))
3395 (defun ps-print-preprint (prefix-arg)
3396 (and prefix-arg
3397 (or (numberp prefix-arg)
3398 (listp prefix-arg))
3399 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
3400 (buffer-name)))
3401 ".ps"))
3402 (prompt (format "Save PostScript to file: (default %s) " name))
3403 (res (read-file-name prompt default-directory name nil)))
3404 (while (cond ((not (file-writable-p res))
3405 (ding)
3406 (setq prompt "is unwritable"))
3407 ((file-exists-p res)
3408 (setq prompt "exists")
3409 (not (y-or-n-p (format "File `%s' exists; overwrite? "
3410 res))))
3411 (t nil))
3412 (setq res (read-file-name
3413 (format "File %s; save PostScript to file: " prompt)
3414 (file-name-directory res) nil nil
3415 (file-name-nondirectory res))))
3416 (if (file-directory-p res)
3417 (expand-file-name name (file-name-as-directory res))
3418 res))))
3420 ;; The following functions implement a simple list-buffering scheme so
3421 ;; that ps-print doesn't have to repeatedly switch between buffers
3422 ;; while spooling. The functions `ps-output' and `ps-output-string' build
3423 ;; up the lists; the function `ps-flush-output' takes the lists and
3424 ;; insert its contents into the spool buffer (*PostScript*).
3426 (defvar ps-string-escape-codes
3427 (let ((table (make-vector 256 nil))
3428 (char ?\000))
3429 ;; control characters
3430 (while (<= char ?\037)
3431 (aset table char (format "\\%03o" char))
3432 (setq char (1+ char)))
3433 ;; printable characters
3434 (while (< char ?\177)
3435 (aset table char (format "%c" char))
3436 (setq char (1+ char)))
3437 ;; DEL and 8-bit characters
3438 (while (<= char ?\377)
3439 (aset table char (format "\\%o" char))
3440 (setq char (1+ char)))
3441 ;; Override ASCII formatting characters with named escape code:
3442 (aset table ?\n "\\n") ; [NL] linefeed
3443 (aset table ?\r "\\r") ; [CR] carriage return
3444 (aset table ?\t "\\t") ; [HT] horizontal tab
3445 (aset table ?\b "\\b") ; [BS] backspace
3446 (aset table ?\f "\\f") ; [NP] form feed
3447 ;; Escape PostScript escape and string delimiter characters:
3448 (aset table ?\\ "\\\\")
3449 (aset table ?\( "\\(")
3450 (aset table ?\) "\\)")
3451 table)
3452 "Vector used to map characters to PostScript string escape codes.")
3454 (defun ps-output-string-prim (string)
3455 (insert "(") ;insert start-string delimiter
3456 (save-excursion ;insert string
3457 (insert (string-as-unibyte string)))
3458 ;; Find and quote special characters as necessary for PS
3459 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
3460 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
3461 (let ((special (following-char)))
3462 (delete-char 1)
3463 (insert (aref ps-string-escape-codes special))))
3464 (goto-char (point-max))
3465 (insert ")")) ;insert end-string delimiter
3467 (defun ps-init-output-queue ()
3468 (setq ps-output-head (list "")
3469 ps-output-tail ps-output-head))
3472 (defun ps-selected-pages ()
3473 (while (progn
3474 (setq ps-first-page (car (car ps-selected-pages))
3475 ps-last-page (cdr (car ps-selected-pages))
3476 ps-selected-pages (cdr ps-selected-pages))
3477 (and ps-selected-pages
3478 (< ps-last-page ps-page-postscript)))))
3481 (defsubst ps-print-page-p ()
3482 (cond ((null ps-first-page))
3483 ((<= ps-page-postscript ps-last-page)
3484 (<= ps-first-page ps-page-postscript))
3485 (ps-selected-pages
3486 (ps-selected-pages)
3487 (and (<= ps-first-page ps-page-postscript)
3488 (<= ps-page-postscript ps-last-page)))
3490 nil)))
3493 (defun ps-output (&rest args)
3494 (when (ps-print-page-p)
3495 (setcdr ps-output-tail args)
3496 (while (cdr ps-output-tail)
3497 (setq ps-output-tail (cdr ps-output-tail)))))
3499 (defun ps-output-string (string)
3500 (ps-output t string))
3502 (defun ps-output-list (the-list)
3503 (mapcar 'ps-output the-list))
3505 ;; Output strings in the list ARGS in the PostScript prologue part.
3506 (defun ps-output-prologue (args)
3507 (ps-output 'prologue (if (stringp args) (list args) args)))
3509 (defun ps-flush-output ()
3510 (save-excursion
3511 (set-buffer ps-spool-buffer)
3512 (goto-char (point-max))
3513 (while ps-output-head
3514 (let ((it (car ps-output-head)))
3515 (cond
3516 ((eq t it)
3517 (setq ps-output-head (cdr ps-output-head))
3518 (ps-output-string-prim (car ps-output-head)))
3519 ((eq 'prologue it)
3520 (setq ps-output-head (cdr ps-output-head))
3521 (save-excursion
3522 (search-backward "\nBeginDoc")
3523 (forward-char 1)
3524 (apply 'insert (car ps-output-head))))
3526 (insert it))))
3527 (setq ps-output-head (cdr ps-output-head))))
3528 (ps-init-output-queue))
3530 (defun ps-insert-file (fname)
3531 (ps-flush-output)
3532 (save-excursion
3533 (set-buffer ps-spool-buffer)
3534 (goto-char (point-max))
3535 (insert-file fname)))
3537 ;; These functions insert the arrays that define the contents of the
3538 ;; headers.
3540 (defun ps-generate-header-line (fonttag &optional content)
3541 (ps-output " [ " fonttag " ")
3542 (cond
3543 ;; Literal strings should be output as is -- the string must
3544 ;; contain its own PS string delimiters, '(' and ')', if necessary.
3545 ((stringp content)
3546 (ps-output content))
3548 ;; Functions are called -- they should return strings; they will be
3549 ;; inserted as strings and the PS string delimiters added.
3550 ((and (symbolp content) (fboundp content))
3551 (ps-output-string (funcall content)))
3553 ;; Variables will have their contents inserted. They should
3554 ;; contain strings, and will be inserted as strings.
3555 ((and (symbolp content) (boundp content))
3556 (ps-output-string (symbol-value content)))
3558 ;; Anything else will get turned into an empty string.
3560 (ps-output-string "")))
3561 (ps-output " ]\n"))
3563 (defun ps-generate-header (name contents)
3564 (ps-output "/" name " [\n")
3565 (if (> ps-header-lines 0)
3566 (let ((count 1))
3567 (ps-generate-header-line "/h0" (car contents))
3568 (while (and (< count ps-header-lines)
3569 (setq contents (cdr contents)))
3570 (ps-generate-header-line "/h1" (car contents))
3571 (setq count (1+ count)))
3572 (ps-output "] def\n"))))
3575 (defun ps-output-boolean (name bool)
3576 (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
3579 (defun ps-background-pages (page-list func)
3580 (if page-list
3581 (mapcar
3582 #'(lambda (pages)
3583 (let ((start (if (consp pages) (car pages) pages))
3584 (end (if (consp pages) (cdr pages) pages)))
3585 (and (integerp start) (integerp end) (<= start end)
3586 (add-to-list 'ps-background-pages (vector start end func)))))
3587 page-list)
3588 (setq ps-background-all-pages (cons func ps-background-all-pages))))
3591 (defconst ps-boundingbox-re
3592 "^%%BoundingBox:\
3593 \\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3596 (defun ps-get-boundingbox ()
3597 (save-excursion
3598 (set-buffer ps-spool-buffer)
3599 (save-excursion
3600 (if (re-search-forward ps-boundingbox-re nil t)
3601 (vector (string-to-number ; lower x
3602 (buffer-substring (match-beginning 1) (match-end 1)))
3603 (string-to-number ; lower y
3604 (buffer-substring (match-beginning 2) (match-end 2)))
3605 (string-to-number ; upper x
3606 (buffer-substring (match-beginning 3) (match-end 3)))
3607 (string-to-number ; upper y
3608 (buffer-substring (match-beginning 4) (match-end 4))))
3609 (vector 0 0 0 0)))))
3612 ;; Emacs understands the %f format; we'll use it to limit color RGB values
3613 ;; to three decimals to cut down some on the size of the PostScript output.
3614 ;; Lucid emacsen will have to make do with %s (princ) for floats.
3616 (defvar ps-float-format (if (eq ps-print-emacs-type 'emacs)
3617 "%0.3f " ; emacs
3618 "%s ")) ; Lucid emacsen
3621 (defun ps-float-format (value &optional default)
3622 (let ((literal (or value default)))
3623 (if literal
3624 (format (if (numberp literal)
3625 ps-float-format
3626 "%s ")
3627 literal)
3628 " ")))
3631 (defun ps-background-text ()
3632 (mapcar
3633 #'(lambda (text)
3634 (setq ps-background-text-count (1+ ps-background-text-count))
3635 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count))
3636 (ps-output-string (nth 0 text)) ; text
3637 (ps-output
3638 "\n"
3639 (ps-float-format (nth 4 text) 200.0) ; font size
3640 (format "/%s " (or (nth 3 text) "Times-Roman")) ; font name
3641 (ps-float-format (nth 6 text)
3642 "PrintHeight PrintPageWidth atan") ; rotation
3643 (ps-float-format (nth 5 text) 0.85) ; gray
3644 (ps-float-format (nth 1 text) "0") ; x position
3645 (ps-float-format (nth 2 text) "0") ; y position
3646 "\nShowBackText} def\n")
3647 (ps-background-pages (nthcdr 7 text) ; page list
3648 (format "ShowBackText-%d\n"
3649 ps-background-text-count)))
3650 ps-print-background-text))
3653 (defun ps-background-image ()
3654 (mapcar
3655 #'(lambda (image)
3656 (let ((image-file (expand-file-name (nth 0 image))))
3657 (when (file-readable-p image-file)
3658 (setq ps-background-image-count (1+ ps-background-image-count))
3659 (ps-output
3660 (format "/ShowBackImage-%d {\n--back-- "
3661 ps-background-image-count)
3662 (ps-float-format (nth 5 image) 0.0) ; rotation
3663 (ps-float-format (nth 3 image) 1.0) ; x scale
3664 (ps-float-format (nth 4 image) 1.0) ; y scale
3665 (ps-float-format (nth 1 image) ; x position
3666 "PrintPageWidth 2 div")
3667 (ps-float-format (nth 2 image) ; y position
3668 "PrintHeight 2 div BottomMargin add")
3669 "\nBeginBackImage\n")
3670 (ps-insert-file image-file)
3671 ;; coordinate adjustment to centralize image
3672 ;; around x and y position
3673 (let ((box (ps-get-boundingbox)))
3674 (save-excursion
3675 (set-buffer ps-spool-buffer)
3676 (save-excursion
3677 (if (re-search-backward "^--back--" nil t)
3678 (replace-match
3679 (format "%s %s"
3680 (ps-float-format
3681 (- (+ (/ (- (aref box 2) (aref box 0)) 2.0)
3682 (aref box 0))))
3683 (ps-float-format
3684 (- (+ (/ (- (aref box 3) (aref box 1)) 2.0)
3685 (aref box 1)))))
3686 t)))))
3687 (ps-output "\nEndBackImage} def\n")
3688 (ps-background-pages (nthcdr 6 image) ; page list
3689 (format "ShowBackImage-%d\n"
3690 ps-background-image-count)))))
3691 ps-print-background-image))
3694 (defun ps-background (page-number)
3695 (let (has-local-background)
3696 (mapcar #'(lambda (range)
3697 (and (<= (aref range 0) page-number)
3698 (<= page-number (aref range 1))
3699 (if has-local-background
3700 (ps-output (aref range 2))
3701 (setq has-local-background t)
3702 (ps-output "/printLocalBackground {\n"
3703 (aref range 2)))))
3704 ps-background-pages)
3705 (and has-local-background (ps-output "} def\n"))))
3708 ;; Return a list of the distinct elements of LIST.
3709 ;; Elements are compared with `equal'.
3710 (defun ps-remove-duplicates (list)
3711 (let (new (tail list))
3712 (while tail
3713 (or (member (car tail) new)
3714 (setq new (cons (car tail) new)))
3715 (setq tail (cdr tail)))
3716 (nreverse new)))
3719 ;; Find the first occurrence of ITEM in LIST.
3720 ;; Return the index of the matching item, or nil if not found.
3721 ;; Elements are compared with `eq'.
3722 (defun ps-alist-position (item list)
3723 (let ((tail list) (index 0) found)
3724 (while tail
3725 (if (setq found (eq (car (car tail)) item))
3726 (setq tail nil)
3727 (setq index (1+ index)
3728 tail (cdr tail))))
3729 (and found index)))
3732 (defconst ps-n-up-database
3733 '((a4
3734 (1 nil 1 1 0)
3735 (2 t 1 2 0)
3736 (4 nil 2 2 0)
3737 (6 t 2 3 1)
3738 (8 t 2 4 0)
3739 (9 nil 3 3 0)
3740 (12 t 3 4 2)
3741 (16 nil 4 4 0)
3742 (18 t 3 6 0)
3743 (20 nil 5 4 1)
3744 (25 nil 5 5 0)
3745 (30 nil 6 5 1)
3746 (32 t 4 8 0)
3747 (36 nil 6 6 0)
3748 (42 nil 7 6 1)
3749 (49 nil 7 7 0)
3750 (50 t 5 10 0)
3751 (56 nil 8 7 1)
3752 (64 nil 8 8 0)
3753 (72 nil 9 8 1)
3754 (81 nil 9 9 0)
3755 (90 nil 10 9 1)
3756 (100 nil 10 10 0))
3758 (1 nil 1 1 0)
3759 (2 t 1 2 0)
3760 (4 nil 2 2 0)
3761 (6 t 2 3 1)
3762 (8 t 2 4 0)
3763 (9 nil 3 3 0)
3764 (12 nil 4 3 1)
3765 (16 nil 4 4 0)
3766 (18 t 3 6 0)
3767 (20 nil 5 4 1)
3768 (25 nil 5 5 0)
3769 (30 nil 6 5 1)
3770 (32 t 4 8 0)
3771 (36 nil 6 6 0)
3772 (42 nil 7 6 1)
3773 (49 nil 7 7 0)
3774 (50 t 5 10 0)
3775 (56 nil 8 7 1)
3776 (64 nil 8 8 0)
3777 (72 nil 9 8 1)
3778 (81 nil 9 9 0)
3779 (90 nil 10 9 1)
3780 (100 nil 10 10 0))
3781 (letter
3782 (1 nil 1 1 0)
3783 (2 t 1 2 0) ; adjusted by PostScript code
3784 (4 nil 2 2 0)
3785 (6 t 2 3 0)
3786 (9 nil 3 3 0)
3787 (12 nil 4 3 1)
3788 (16 nil 4 4 0)
3789 (20 nil 5 4 1)
3790 (25 nil 5 5 0)
3791 (30 nil 6 5 1)
3792 (36 nil 6 6 0)
3793 (40 t 5 8 0)
3794 (42 nil 7 6 1)
3795 (49 nil 7 7 0)
3796 (56 nil 8 7 1)
3797 (64 nil 8 8 0)
3798 (72 nil 9 8 1)
3799 (81 nil 9 9 0)
3800 (90 nil 10 9 1)
3801 (100 nil 10 10 0))
3802 (legal
3803 (1 nil 1 1 0)
3804 (2 t 1 2 0)
3805 (4 nil 2 2 0)
3806 (6 nil 3 2 1)
3807 (9 nil 3 3 0)
3808 (10 t 2 5 0)
3809 (12 nil 4 3 1)
3810 (16 nil 4 4 0)
3811 (20 nil 5 4 1)
3812 (25 nil 5 5 0)
3813 (30 nil 6 5 1)
3814 (36 nil 6 6 0)
3815 (42 nil 7 6 1)
3816 (49 nil 7 7 0)
3817 (56 nil 8 7 1)
3818 (64 nil 8 8 0)
3819 (70 t 5 14 0)
3820 (72 nil 9 8 1)
3821 (81 nil 9 9 0)
3822 (90 nil 10 9 1)
3823 (100 nil 10 10 0))
3824 (letter-small
3825 (1 nil 1 1 0)
3826 (2 t 1 2 0) ; adjusted by PostScript code
3827 (4 nil 2 2 0)
3828 (6 t 2 3 0)
3829 (9 nil 3 3 0)
3830 (12 t 3 4 1)
3831 (15 t 3 5 0)
3832 (16 nil 4 4 0)
3833 (20 nil 5 4 1)
3834 (25 nil 5 5 0)
3835 (28 t 4 7 0)
3836 (30 nil 6 5 1)
3837 (36 nil 6 6 0)
3838 (40 t 5 8 0)
3839 (42 nil 7 6 1)
3840 (49 nil 7 7 0)
3841 (56 nil 8 7 1)
3842 (60 t 6 10 0)
3843 (64 nil 8 8 0)
3844 (72 ni 9 8 1)
3845 (81 nil 9 9 0)
3846 (84 t 7 12 0)
3847 (90 nil 10 9 1)
3848 (100 nil 10 10 0))
3849 (tabloid
3850 (1 nil 1 1 0)
3851 (2 t 1 2 0)
3852 (4 nil 2 2 0)
3853 (6 t 2 3 1)
3854 (8 t 2 4 0)
3855 (9 nil 3 3 0)
3856 (12 nil 4 3 1)
3857 (16 nil 4 4 0)
3858 (20 nil 5 4 1)
3859 (25 nil 5 5 0)
3860 (30 nil 6 5 1)
3861 (36 nil 6 6 0)
3862 (42 nil 7 6 1)
3863 (49 nil 7 7 0)
3864 (56 nil 8 7 1)
3865 (64 nil 8 8 0)
3866 (72 nil 9 8 1)
3867 (81 nil 9 9 0)
3868 (84 t 6 14 0)
3869 (90 nil 10 9 1)
3870 (100 nil 10 10 0))
3871 ;; Ledger paper size is a special case, it is the only paper size where the
3872 ;; normal size is landscaped, that is, the height is smaller than width.
3873 ;; So, we use the special value `pag' in the `landscape' field.
3874 (ledger
3875 (1 nil 1 1 0)
3876 (2 pag 1 2 0)
3877 (4 nil 2 2 0)
3878 (6 pag 2 3 1)
3879 (8 pag 2 4 0)
3880 (9 nil 3 3 0)
3881 (12 nil 4 3 1)
3882 (16 nil 4 4 0)
3883 (20 nil 5 4 1)
3884 (25 nil 5 5 0)
3885 (30 nil 6 5 1)
3886 (36 nil 6 6 0)
3887 (42 nil 7 6 1)
3888 (49 nil 7 7 0)
3889 (56 nil 8 7 1)
3890 (64 nil 8 8 0)
3891 (72 nil 9 8 1)
3892 (81 nil 9 9 0)
3893 (84 pag 6 14 0)
3894 (90 nil 10 9 1)
3895 (100 nil 10 10 0))
3896 (statement
3897 (1 nil 1 1 0)
3898 (2 t 1 2 0)
3899 (4 nil 2 2 0)
3900 (6 nil 3 2 1)
3901 (9 nil 3 3 0)
3902 (10 t 2 5 0)
3903 (12 nil 4 3 1)
3904 (16 nil 4 4 0)
3905 (20 nil 5 4 1)
3906 (21 t 3 7 0)
3907 (25 nil 5 5 0)
3908 (30 nil 6 5 1)
3909 (36 nil 6 6 0)
3910 (40 t 4 10 0)
3911 (42 nil 7 6 1)
3912 (49 nil 7 7 0)
3913 (56 nil 8 7 1)
3914 (60 t 5 12 0)
3915 (64 nil 8 8 0)
3916 (72 nil 9 8 1)
3917 (81 nil 9 9 0)
3918 (90 nil 10 9 1)
3919 (100 nil 10 10 0))
3920 (executive
3921 (1 nil 1 1 0)
3922 (2 t 1 2 0) ; adjusted by PostScript code
3923 (4 nil 2 2 0)
3924 (6 t 2 3 0)
3925 (9 nil 3 3 0)
3926 (12 nil 4 3 1)
3927 (16 nil 4 4 0)
3928 (20 nil 5 4 1)
3929 (25 nil 5 5 0)
3930 (28 t 4 7 0)
3931 (30 nil 6 5 1)
3932 (36 nil 6 6 0)
3933 (42 nil 7 6 1)
3934 (45 t 5 9 0)
3935 (49 nil 7 7 0)
3936 (56 nil 8 7 1)
3937 (60 t 6 10 0)
3938 (64 nil 8 8 0)
3939 (72 nil 9 8 1)
3940 (81 nil 9 9 0)
3941 (84 t 7 12 0)
3942 (90 nil 10 9 1)
3943 (100 nil 10 10 0))
3944 (a4small
3945 (1 nil 1 1 0)
3946 (2 t 1 2 0)
3947 (4 nil 2 2 0)
3948 (6 t 2 3 1)
3949 (8 t 2 4 0)
3950 (9 nil 3 3 0)
3951 (12 nil 4 3 1)
3952 (16 nil 4 4 0)
3953 (18 t 3 6 0)
3954 (20 nil 5 4 1)
3955 (25 nil 5 5 0)
3956 (30 nil 6 5 1)
3957 (32 t 4 8 0)
3958 (36 nil 6 6 0)
3959 (42 nil 7 6 1)
3960 (49 nil 7 7 0)
3961 (50 t 5 10 0)
3962 (56 nil 8 7 1)
3963 (64 nil 8 8 0)
3964 (72 nil 9 8 1)
3965 (78 t 6 13 0)
3966 (81 nil 9 9 0)
3967 (90 nil 10 9 1)
3968 (100 nil 10 10 0))
3970 (1 nil 1 1 0)
3971 (2 t 1 2 0)
3972 (4 nil 2 2 0)
3973 (6 t 2 3 1)
3974 (8 t 2 4 0)
3975 (9 nil 3 3 0)
3976 (12 nil 4 3 1)
3977 (16 nil 4 4 0)
3978 (18 t 3 6 0)
3979 (20 nil 5 4 1)
3980 (25 nil 5 5 0)
3981 (30 nil 6 5 1)
3982 (32 t 4 8 0)
3983 (36 nil 6 6 0)
3984 (42 nil 7 6 1)
3985 (49 nil 7 7 0)
3986 (50 t 5 10 0)
3987 (56 nil 8 7 1)
3988 (64 nil 8 8 0)
3989 (72 nil 9 8 1)
3990 (81 nil 9 9 0)
3991 (90 nil 10 9 1)
3992 (100 nil 10 10 0))
3994 (1 nil 1 1 0)
3995 (2 t 1 2 0)
3996 (4 nil 2 2 0)
3997 (6 t 2 3 1)
3998 (8 t 2 4 0)
3999 (9 nil 3 3 0)
4000 (12 nil 4 3 1)
4001 (16 nil 4 4 0)
4002 (18 t 3 6 0)
4003 (20 nil 5 4 1)
4004 (25 nil 5 5 0)
4005 (30 nil 6 5 1)
4006 (32 t 4 8 0)
4007 (36 nil 6 6 0)
4008 (42 nil 7 6 1)
4009 (49 nil 7 7 0)
4010 (50 t 5 10 0)
4011 (56 nil 8 7 1)
4012 (64 nil 8 8 0)
4013 (72 nil 9 8 0)
4014 (81 nil 9 9 0)
4015 (90 nil 10 9 1)
4016 (98 t 7 14 0)
4017 (100 nil 10 10 0)))
4018 "Alist which is the page matrix database used for N-up printing.
4020 Each element has the following form:
4022 (PAGE
4023 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
4024 ...)
4026 Where:
4027 PAGE is the page size used (see `ps-paper-type').
4028 MAX is the maximum elements of this page matrix.
4029 LANDSCAPE specifies if page matrix is landscaped, has the following valid
4030 values:
4031 nil the sheet is in portrait mode.
4032 t the sheet is in landscape mode.
4033 pag the sheet is in portrait mode and page is in landscape mode.
4034 LINES is the number of lines of page matrix.
4035 COLUMNS is the number of columns of page matrix.
4036 COL-MISSING is the number of columns missing to fill the sheet.")
4039 (defmacro ps-n-up-landscape (mat) `(nth 1 ,mat))
4040 (defmacro ps-n-up-lines (mat) `(nth 2 ,mat))
4041 (defmacro ps-n-up-columns (mat) `(nth 3 ,mat))
4042 (defmacro ps-n-up-missing (mat) `(nth 4 ,mat))
4045 (defun ps-n-up-printing ()
4046 ;; force `ps-n-up-printing' be in range 1 to 100.
4047 (setq ps-n-up-printing (max (min ps-n-up-printing 100) 1))
4048 ;; find suitable page matrix for a given `ps-paper-type'.
4049 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database))))
4050 (and the-list
4051 (while (> ps-n-up-printing (caar the-list))
4052 (setq the-list (cdr the-list))))
4053 (car the-list)))
4056 (defconst ps-n-up-filling-database
4057 '((left-top
4058 "PageWidth" ; N-Up-XColumn
4059 "0" ; N-Up-YColumn
4060 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
4061 "LandscapePageHeight neg" ; N-Up-YLine
4062 "N-Up-Lines" ; N-Up-Repeat
4063 "N-Up-Columns" ; N-Up-End
4064 "0" ; N-Up-XStart
4065 "0") ; N-Up-YStart
4066 (left-bottom
4067 "PageWidth" ; N-Up-XColumn
4068 "0" ; N-Up-YColumn
4069 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
4070 "LandscapePageHeight" ; N-Up-YLine
4071 "N-Up-Lines" ; N-Up-Repeat
4072 "N-Up-Columns" ; N-Up-End
4073 "0" ; N-Up-XStart
4074 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
4075 (right-top
4076 "PageWidth neg" ; N-Up-XColumn
4077 "0" ; N-Up-YColumn
4078 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
4079 "LandscapePageHeight neg" ; N-Up-YLine
4080 "N-Up-Lines" ; N-Up-Repeat
4081 "N-Up-Columns" ; N-Up-End
4082 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
4083 "0") ; N-Up-YStart
4084 (right-bottom
4085 "PageWidth neg" ; N-Up-XColumn
4086 "0" ; N-Up-YColumn
4087 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
4088 "LandscapePageHeight" ; N-Up-YLine
4089 "N-Up-Lines" ; N-Up-Repeat
4090 "N-Up-Columns" ; N-Up-End
4091 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
4092 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
4093 (top-left
4094 "0" ; N-Up-XColumn
4095 "LandscapePageHeight neg" ; N-Up-YColumn
4096 "PageWidth" ; N-Up-XLine
4097 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
4098 "N-Up-Columns" ; N-Up-Repeat
4099 "N-Up-Lines" ; N-Up-End
4100 "0" ; N-Up-XStart
4101 "0") ; N-Up-YStart
4102 (bottom-left
4103 "0" ; N-Up-XColumn
4104 "LandscapePageHeight" ; N-Up-YColumn
4105 "PageWidth" ; N-Up-XLine
4106 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
4107 "N-Up-Columns" ; N-Up-Repeat
4108 "N-Up-Lines" ; N-Up-End
4109 "0" ; N-Up-XStart
4110 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
4111 (top-right
4112 "0" ; N-Up-XColumn
4113 "LandscapePageHeight neg" ; N-Up-YColumn
4114 "PageWidth neg" ; N-Up-XLine
4115 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
4116 "N-Up-Columns" ; N-Up-Repeat
4117 "N-Up-Lines" ; N-Up-End
4118 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
4119 "0") ; N-Up-YStart
4120 (bottom-right
4121 "0" ; N-Up-XColumn
4122 "LandscapePageHeight" ; N-Up-YColumn
4123 "PageWidth neg" ; N-Up-XLine
4124 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
4125 "N-Up-Columns" ; N-Up-Repeat
4126 "N-Up-Lines" ; N-Up-End
4127 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
4128 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
4129 "Alist for n-up printing initializations.
4131 Each element has the following form:
4133 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
4135 Where:
4136 KIND is a valid value of `ps-n-up-filling'.
4137 XCOL YCOL are the relative position for the next column.
4138 XLIN YLIN are the relative position for the beginning of next line.
4139 REPEAT is the number of repetions for external loop.
4140 END is the number of repetions for internal loop and also the number of pages in
4141 a row.
4142 XSTART YSTART are the relative position for the first page in a sheet.")
4145 (defun ps-n-up-filling ()
4146 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database)
4147 (assq 'left-top ps-n-up-filling-database))))
4150 (defmacro ps-n-up-xcolumn (init) `(nth 0 ,init))
4151 (defmacro ps-n-up-ycolumn (init) `(nth 1 ,init))
4152 (defmacro ps-n-up-xline (init) `(nth 2 ,init))
4153 (defmacro ps-n-up-yline (init) `(nth 3 ,init))
4154 (defmacro ps-n-up-repeat (init) `(nth 4 ,init))
4155 (defmacro ps-n-up-end (init) `(nth 5 ,init))
4156 (defmacro ps-n-up-xstart (init) `(nth 6 ,init))
4157 (defmacro ps-n-up-ystart (init) `(nth 7 ,init))
4160 (defconst ps-error-handler-alist
4161 '((none . 0)
4162 (paper . 1)
4163 (system . 2)
4164 (paper-and-system . 3))
4165 "Alist for error handler message")
4168 (defun ps-begin-file ()
4169 (ps-get-page-dimensions)
4170 (setq ps-page-postscript 0
4171 ps-page-order 0
4172 ps-background-text-count 0
4173 ps-background-image-count 0
4174 ps-background-pages nil
4175 ps-background-all-pages nil)
4177 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
4178 (tumble (if ps-landscape-mode (not ps-spool-tumble) ps-spool-tumble))
4179 (n-up (ps-n-up-printing))
4180 (n-up-filling (ps-n-up-filling)))
4181 (and ps-n-up-on (setq tumble (not tumble)))
4182 (ps-output
4183 ps-adobe-tag
4184 "%%Title: " (buffer-name) ; Take job name from name of
4185 ; first buffer printed
4186 "\n%%Creator: " (user-full-name)
4187 " (using ps-print v" ps-print-version
4188 ")\n%%CreationDate: "
4189 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy)
4190 "\n%%Orientation: "
4191 (if ps-landscape-mode "Landscape" "Portrait")
4192 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
4193 (mapconcat 'identity
4194 (ps-remove-duplicates
4195 (append (ps-fonts 'ps-font-for-text)
4196 (list (ps-font 'ps-font-for-header 'normal)
4197 (ps-font 'ps-font-for-header 'bold))))
4198 "\n%%+ font ")
4199 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions)
4200 (format " %d" (round (ps-page-dimensions-get-width dimensions)))
4201 (format " %d" (round (ps-page-dimensions-get-height dimensions)))
4202 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
4203 (if ps-spool-duplex
4204 (if tumble " duplex(tumble)\n" " duplex\n")
4205 "\n"))
4207 (ps-insert-string ps-print-prologue-header)
4209 (ps-output "%%EndComments\n%%BeginDefaults\n%%PageMedia: "
4210 (ps-page-dimensions-get-media dimensions)
4211 "\n%%EndDefaults\n\n%%BeginPrologue\n\n"
4212 "/languagelevel where{pop}{/languagelevel 1 def}ifelse\n"
4213 (format "/ErrorMessage %s def\n\n"
4214 (or (cdr (assoc ps-error-handler-message
4215 ps-error-handler-alist))
4216 1)) ; send to paper
4217 ps-print-prologue-0
4218 "\n%%BeginProcSet: UserDefinedPrologue\n\n")
4220 (ps-insert-string ps-user-defined-prologue)
4222 (ps-output "\n%%EndProcSet\n\n")
4224 (ps-output-boolean "LandscapeMode "
4225 (or ps-landscape-mode
4226 (eq (ps-n-up-landscape n-up) 'pag)))
4227 (ps-output-boolean "UpsideDown " ps-print-upside-down)
4228 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns)
4230 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height)
4231 (format "/PrintPageWidth %s def\n"
4232 (- (* (+ ps-print-width ps-inter-column)
4233 ps-number-of-columns)
4234 ps-inter-column))
4235 (format "/PrintWidth %s def\n" ps-print-width)
4236 (format "/PrintHeight %s def\n" ps-print-height)
4238 (format "/LeftMargin %s def\n" ps-left-margin)
4239 (format "/RightMargin %s def\n" ps-right-margin)
4240 (format "/InterColumn %s def\n" ps-inter-column)
4242 (format "/BottomMargin %s def\n" ps-bottom-margin)
4243 (format "/TopMargin %s def\n" ps-top-margin) ; not used
4244 (format "/HeaderOffset %s def\n" ps-header-offset)
4245 (format "/HeaderPad %s def\n" ps-header-pad))
4247 (ps-output-boolean "PrintHeader " ps-print-header)
4248 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header)
4249 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame)
4250 (ps-output-boolean "SwitchHeader " (if (eq ps-switch-header 'duplex)
4251 ps-spool-duplex
4252 ps-switch-header))
4253 (ps-output-boolean "ShowNofN " ps-show-n-of-n)
4254 (ps-output-boolean "DuplexValue " ps-spool-duplex)
4255 (ps-output-boolean "TumbleValue " tumble)
4257 (let ((line-height (ps-line-height 'ps-font-for-text)))
4258 (ps-output (format "/LineHeight %s def\n" line-height)
4259 (format "/LinesPerColumn %d def\n"
4260 (round (/ (+ ps-print-height
4261 (* line-height 0.45))
4262 line-height)))))
4264 (ps-output-boolean "WarnPaperSize " ps-warn-paper-type)
4265 (ps-output-boolean "Zebra " ps-zebra-stripes)
4266 (ps-output-boolean "ZebraFollow " ps-zebra-stripe-follow)
4267 (ps-output-boolean "PrintLineNumber " ps-line-number)
4268 (ps-output-boolean "SyncLineZebra " (not (integerp ps-line-number-step)))
4269 (ps-output (format "/PrintLineStep %d def\n"
4270 (if (integerp ps-line-number-step)
4271 ps-line-number-step
4272 ps-zebra-stripe-height))
4273 (format "/PrintLineStart %d def\n" ps-line-number-start)
4274 (format "/ZebraHeight %d def\n" ps-zebra-stripe-height)
4275 "/ZebraColor "
4276 (ps-format-color ps-zebra-color 0.95)
4277 "def\n/BackgroundColor "
4278 (ps-format-color ps-default-bg 1.0)
4279 "def\n/UseSetpagedevice "
4280 (if (eq ps-spool-config 'setpagedevice)
4281 "/setpagedevice where{pop languagelevel 2 eq}{false}ifelse"
4282 "false")
4283 " def\n\n/PageWidth "
4284 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
4285 (format "/N-Up %d def\n" ps-n-up-printing))
4286 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up) t))
4287 (ps-output-boolean "N-Up-Border " ps-n-up-border-p)
4288 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up))
4289 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up))
4290 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up))
4291 (format "/N-Up-Margin %s def\n" ps-n-up-margin)
4292 "/N-Up-Repeat "
4293 (if ps-landscape-mode
4294 (ps-n-up-end n-up-filling)
4295 (ps-n-up-repeat n-up-filling))
4296 " def\n/N-Up-End "
4297 (if ps-landscape-mode
4298 (ps-n-up-repeat n-up-filling)
4299 (ps-n-up-end n-up-filling))
4300 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling)
4301 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling)
4302 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling)
4303 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling)
4304 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling)
4305 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling) " def\n")
4307 (ps-background-text)
4308 (ps-background-image)
4309 (setq ps-background-all-pages (nreverse ps-background-all-pages)
4310 ps-background-pages (nreverse ps-background-pages))
4312 (ps-output "\n" ps-print-prologue-1)
4314 (ps-output "\n/printGlobalBackground {\n")
4315 (ps-output-list ps-background-all-pages)
4316 (ps-output "} def\n/printLocalBackground {\n} def\n")
4318 ;; Header fonts
4319 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
4320 ps-header-title-font-size-internal
4321 (ps-font 'ps-font-for-header 'bold))
4322 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
4323 ps-header-font-size-internal
4324 (ps-font 'ps-font-for-header 'normal)))
4326 (ps-output "\n" ps-print-prologue-2 "\n")
4328 ;; Text fonts
4329 (let ((font (ps-font-alist 'ps-font-for-text))
4330 (i 0))
4331 (while font
4332 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
4334 ps-font-size-internal
4335 (ps-font 'ps-font-for-text (car (car font)))))
4336 (setq font (cdr font)
4337 i (1+ i))))
4339 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database))))
4340 (ps-output (format "/SpaceWidthRatio %f def\n"
4341 (/ (ps-lookup 'space-width) (ps-lookup 'size)))))
4343 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
4344 (unless (eq ps-spool-config 'lpr-switches)
4345 (ps-output "\n%%BeginFeature: *Duplex "
4346 (ps-boolean-capitalized ps-spool-duplex)
4347 " *Tumble "
4348 (ps-boolean-capitalized tumble)
4349 "\n\n"
4350 ps-print-duplex-feature
4351 "\n%%EndFeature\n")))
4352 (ps-output "\n%%BeginFeature: *ManualFeed "
4353 (ps-boolean-capitalized ps-manual-feed)
4354 "\nBMark /ManualFeed "
4355 (ps-boolean-constant ps-manual-feed)
4356 " EMark setpagedevice\n%%EndFeature\n"
4357 "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n")
4358 (and ps-banner-page-when-duplexing
4359 (ps-output "\n%%Page: banner 0\nsave showpage restore\n")))
4362 (defun ps-format-color (color &optional default)
4363 (let ((the-color (if (stringp color)
4364 (ps-color-scale color)
4365 color)))
4366 (if (and the-color (listp the-color))
4367 (concat "["
4368 (format ps-color-format
4369 (nth 0 the-color)
4370 (nth 1 the-color)
4371 (nth 2 the-color))
4372 "] ")
4373 (ps-float-format (if (numberp the-color) the-color default)))))
4376 (defun ps-insert-string (prologue)
4377 (let ((str (if (functionp prologue)
4378 (funcall prologue)
4379 prologue)))
4380 (and (stringp str)
4381 (ps-output str))))
4384 (defun ps-boolean-capitalized (bool)
4385 (if bool "True" "False"))
4388 (defun ps-boolean-constant (bool)
4389 (if bool "true" "false"))
4392 (defun ps-header-dirpart ()
4393 (let ((fname (buffer-file-name)))
4394 (if fname
4395 (if (string-equal (buffer-name) (file-name-nondirectory fname))
4396 (abbreviate-file-name (file-name-directory fname))
4397 fname)
4398 "")))
4401 (defun ps-get-buffer-name ()
4402 (cond
4403 ;; Indulge Jim this little easter egg:
4404 ((string= (buffer-name) "ps-print.el")
4405 "Hey, Cool! It's ps-print.el!!!")
4406 ;; Indulge Jack this other little easter egg:
4407 ((string= (buffer-name) "sokoban.el")
4408 "Super! C'est sokoban.el!")
4409 (t (concat
4410 (and ps-printing-region-p "Subset of: ")
4411 (buffer-name)
4412 (and (buffer-modified-p) " (unsaved)")))))
4415 (defun ps-get-font-size (font-sym)
4416 (let ((font-size (symbol-value font-sym)))
4417 (cond ((numberp font-size)
4418 font-size)
4419 ((and (consp font-size)
4420 (numberp (car font-size))
4421 (numberp (cdr font-size)))
4422 (if ps-landscape-mode
4423 (car font-size)
4424 (cdr font-size)))
4426 (error "Invalid font size `%S' for `%S'" font-size font-sym)))))
4429 (defun ps-begin-job ()
4430 ;; prologue files
4431 (let ((last-char (aref ps-postscript-code-directory
4432 (1- (length ps-postscript-code-directory)))))
4433 (or (eq last-char ?/)
4434 (and ps-windows-system (eq last-char ?\\))
4435 (setq ps-postscript-code-directory
4436 (concat ps-postscript-code-directory "/"))))
4437 (or (equal ps-mark-code-directory ps-postscript-code-directory)
4438 (setq ps-print-prologue-0 (ps-prologue-file 0)
4439 ps-print-prologue-1 (ps-prologue-file 1)
4440 ps-print-prologue-2 (ps-prologue-file 2)
4441 ps-print-duplex-feature (ps-prologue-file 3)
4442 ps-mark-code-directory ps-postscript-code-directory))
4443 ;; selected pages
4444 (let (new page)
4445 (while ps-selected-pages
4446 (setq page (car ps-selected-pages)
4447 ps-selected-pages (cdr ps-selected-pages))
4448 (cond ((integerp page)
4449 (and (> page 0)
4450 (setq new (cons (cons page page) new))))
4451 ((consp page)
4452 (and (integerp (car page)) (integerp (cdr page))
4453 (> (car page) 0)
4454 (<= (car page) (cdr page))
4455 (setq new (cons page new))))))
4456 (setq ps-selected-pages (sort new #'(lambda (one other)
4457 (< (car one) (car other))))
4458 ps-last-selected-pages ps-selected-pages
4459 ps-first-page nil
4460 ps-last-page nil))
4461 ;; face background
4462 (or (listp ps-use-face-background)
4463 (setq ps-use-face-background t))
4464 ;; line number
4465 (and (integerp ps-line-number-step)
4466 (<= ps-line-number-step 0)
4467 (setq ps-line-number-step 1))
4468 (setq ps-n-up-on (> ps-n-up-printing 1)
4469 ps-line-number-start (max 1 (min ps-line-number-start
4470 (if (integerp ps-line-number-step)
4471 ps-line-number-step
4472 ps-zebra-stripe-height))))
4473 ;; spooling buffer
4474 (save-excursion
4475 (set-buffer ps-spool-buffer)
4476 (goto-char (point-max))
4477 (and (re-search-backward "^%%Trailer$" nil t)
4478 (delete-region (match-beginning 0) (point-max))))
4479 ;; miscellaneous
4480 (setq ps-showline-count (car ps-printing-region)
4481 ps-page-count 0
4482 ps-font-size-internal (ps-get-font-size 'ps-font-size)
4483 ps-header-font-size-internal (ps-get-font-size 'ps-header-font-size)
4484 ps-header-title-font-size-internal
4485 (ps-get-font-size 'ps-header-title-font-size)
4486 ps-control-or-escape-regexp
4487 (cond ((eq ps-print-control-characters '8-bit)
4488 (string-as-unibyte "[\000-\037\177-\377]"))
4489 ((eq ps-print-control-characters 'control-8-bit)
4490 (string-as-unibyte "[\000-\037\177-\237]"))
4491 ((eq ps-print-control-characters 'control)
4492 "[\000-\037\177]")
4493 (t "[\t\n\f]"))
4494 ps-default-foreground (ps-rgb-color ps-default-fg 0.0)
4495 ps-default-color (and ps-print-color-p ps-default-foreground)
4496 ps-current-color ps-default-color
4497 ;; Set the color scale. We do it here instead of in the defvar so
4498 ;; that ps-print can be dumped into emacs. This expression can't be
4499 ;; evaluated at dump-time because X isn't initialized.
4500 ps-color-p (and ps-print-color-p (ps-color-device))
4501 ps-print-color-scale (if ps-color-p
4502 (float (car (ps-color-values "white")))
4503 1.0)))
4506 (defun ps-rgb-color (color default)
4507 (cond ((and color (listp color)) color)
4508 ((stringp color) (ps-color-scale color))
4509 ((numberp color) (list color color color))
4510 (t (list default default default))
4514 (defmacro ps-page-number ()
4515 `(1+ (/ (1- ps-page-count) ps-number-of-columns)))
4517 (defun ps-end-file (needs-begin-file)
4518 (ps-flush-output)
4519 ;; Back to the PS output buffer to set the last page n-up printing
4520 (save-excursion
4521 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing))
4522 case-fold-search)
4523 (set-buffer ps-spool-buffer)
4524 (goto-char (point-max))
4525 (and (> pages-per-sheet 0)
4526 (re-search-backward "^[0-9]+ BeginSheet$" nil t)
4527 (replace-match (format "%d BeginSheet" pages-per-sheet) t))))
4528 ;; Set dummy page
4529 (and ps-spool-duplex (= (mod ps-page-order 2) 1)
4530 (let (ps-first-page)
4531 (ps-dummy-page)))
4532 ;; Set end of PostScript file
4533 (or ps-first-page
4534 (ps-output "EndSheet\n"))
4535 (setq ps-first-page nil) ; disable selected pages
4536 (ps-output "\n%%Trailer\n%%Pages: "
4537 (format "%d"
4538 (if (and needs-begin-file ps-banner-page-when-duplexing)
4539 (1+ ps-page-order)
4540 ps-page-order))
4541 "\n\nEndDoc\n\n%%EOF\n"))
4544 (defun ps-next-page ()
4545 (ps-end-page)
4546 (ps-flush-output)
4547 (ps-begin-page))
4550 (defun ps-header-sheet ()
4551 ;; Print only when a new sheet begins.
4552 (let ((print-posterior (ps-print-page-p)))
4553 (setq ps-page-postscript (1+ ps-page-postscript))
4554 (cond ((ps-print-page-p)
4555 (setq ps-page-order (1+ ps-page-order))
4556 (and print-posterior (> ps-page-order 1)
4557 (ps-output "EndSheet\n"))
4558 (ps-output (if ps-n-up-on
4559 (format "\n%%%%Page: (%d \\(%d\\)) %d\n"
4560 ps-page-order ps-page-postscript ps-page-order)
4561 (format "\n%%%%Page: %d %d\n"
4562 ps-page-postscript ps-page-order))
4563 (format "%d BeginSheet\nBeginDSCPage\n"
4564 ps-n-up-printing)))
4565 (print-posterior
4566 (let (ps-first-page)
4567 (ps-output "EndSheet\n"))))))
4570 (defsubst ps-header-page ()
4571 ;; set total line and page number when printing has finished
4572 ;; (see `ps-generate')
4573 (run-hooks
4574 (if (prog1
4575 (zerop (mod ps-page-count ps-number-of-columns))
4576 (setq ps-page-count (1+ ps-page-count)))
4577 (prog1
4578 (if (zerop (mod ps-page-postscript ps-n-up-printing))
4579 ;; Print only when a new sheet begins.
4580 (progn
4581 (ps-header-sheet)
4582 'ps-print-begin-sheet-hook)
4583 ;; Print only when a new page begins.
4584 (setq ps-page-postscript (1+ ps-page-postscript))
4585 (ps-output "BeginDSCPage\n")
4586 'ps-print-begin-page-hook)
4587 (ps-background ps-page-postscript))
4588 ;; Print only when a new column begins.
4589 (ps-output "BeginDSCPage\n")
4590 'ps-print-begin-column-hook)))
4592 (defun ps-begin-page ()
4593 (ps-get-page-dimensions)
4594 (setq ps-width-remaining ps-print-width
4595 ps-height-remaining ps-print-height)
4597 (ps-header-page)
4599 (ps-output (format "/LineNumber %d def\n" ps-showline-count)
4600 (format "/PageNumber %d def\n" (if ps-print-only-one-header
4601 (ps-page-number)
4602 ps-page-count)))
4604 (when ps-print-header
4605 (ps-generate-header "HeaderLinesLeft" ps-left-header)
4606 (ps-generate-header "HeaderLinesRight" ps-right-header)
4607 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
4609 (ps-output "BeginPage\n")
4610 (ps-set-font ps-current-font)
4611 (ps-set-bg ps-current-bg)
4612 (ps-set-color ps-current-color)
4613 (ps-mule-begin-page))
4615 (defun ps-end-page ()
4616 (ps-output "EndPage\nEndDSCPage\n"))
4618 (defun ps-dummy-page ()
4619 (let ((ps-n-up-printing 0))
4620 (ps-header-sheet))
4621 (ps-output "/PrintHeader false def
4622 /ColumnIndex 0 def
4623 /PrintLineNumber false def
4624 BeginPage
4625 EndPage
4626 EndDSCPage\n")
4627 (setq ps-page-postscript ps-n-up-printing))
4629 (defun ps-next-line ()
4630 (setq ps-showline-count (1+ ps-showline-count))
4631 (let ((lh (ps-line-height 'ps-font-for-text)))
4632 (if (< ps-height-remaining lh)
4633 (ps-next-page)
4634 (setq ps-width-remaining ps-print-width
4635 ps-height-remaining (- ps-height-remaining lh))
4636 (ps-output "HL\n"))))
4638 (defun ps-continue-line ()
4639 (let ((lh (ps-line-height 'ps-font-for-text)))
4640 (if (< ps-height-remaining lh)
4641 (ps-next-page)
4642 (setq ps-width-remaining ps-print-width
4643 ps-height-remaining (- ps-height-remaining lh))
4644 (ps-output "SL\n"))))
4646 (defun ps-find-wrappoint (from to char-width)
4647 (let ((avail (truncate (/ ps-width-remaining char-width)))
4648 (todo (- to from)))
4649 (if (< todo avail)
4650 (cons to (* todo char-width))
4651 (cons (+ from avail) ps-width-remaining))))
4653 (defun ps-basic-plot-string (from to &optional bg-color)
4654 (let* ((wrappoint (ps-find-wrappoint from to
4655 (ps-avg-char-width 'ps-font-for-text)))
4656 (to (car wrappoint))
4657 (string (buffer-substring-no-properties from to)))
4658 (ps-mule-prepare-ascii-font string)
4659 (ps-output-string string)
4660 (ps-output " S\n")
4661 wrappoint))
4663 (defun ps-basic-plot-whitespace (from to &optional bg-color)
4664 (let* ((wrappoint (ps-find-wrappoint from to
4665 (ps-space-width 'ps-font-for-text)))
4666 (to (car wrappoint)))
4667 (ps-output (format "%d W\n" (- to from)))
4668 wrappoint))
4670 (defun ps-plot (plotfunc from to &optional bg-color)
4671 (while (< from to)
4672 (let* ((wrappoint (funcall plotfunc from to bg-color))
4673 (plotted-to (car wrappoint))
4674 (plotted-width (cdr wrappoint)))
4675 (setq from plotted-to
4676 ps-width-remaining (- ps-width-remaining plotted-width))
4677 (if (< from to)
4678 (ps-continue-line))))
4679 (if ps-razzle-dazzle
4680 (let* ((q-todo (- (point-max) (point-min)))
4681 (q-done (- (point) (point-min)))
4682 (chunkfrac (/ q-todo 8))
4683 (chunksize (min chunkfrac 1000)))
4684 (if (> (- q-done ps-razchunk) chunksize)
4685 (progn
4686 (setq ps-razchunk q-done)
4687 (message "Formatting...%3d%%"
4688 (if (< q-todo 100)
4689 (/ (* 100 q-done) q-todo)
4690 (/ q-done (/ q-todo 100)))
4691 ))))))
4693 (defvar ps-last-font nil)
4695 (defun ps-set-font (font)
4696 (setq ps-last-font (format "f%d" (setq ps-current-font font)))
4697 (ps-output (format "/%s F\n" ps-last-font)))
4699 (defun ps-set-bg (color)
4700 (if (setq ps-current-bg color)
4701 (ps-output (format ps-color-format
4702 (nth 0 color) (nth 1 color) (nth 2 color))
4703 " true BG\n")
4704 (ps-output "false BG\n")))
4706 (defun ps-set-color (color)
4707 (setq ps-current-color (or color ps-default-foreground))
4708 (ps-output (format ps-color-format
4709 (nth 0 ps-current-color)
4710 (nth 1 ps-current-color) (nth 2 ps-current-color))
4711 " FG\n"))
4714 (defvar ps-current-effect 0)
4717 (defun ps-plot-region (from to font &optional fg-color bg-color effects)
4718 (if (not (equal font ps-current-font))
4719 (ps-set-font font))
4721 ;; Specify a foreground color only if one's specified and it's
4722 ;; different than the current.
4723 (if (not (equal fg-color ps-current-color))
4724 (ps-set-color fg-color))
4726 (if (not (equal bg-color ps-current-bg))
4727 (ps-set-bg bg-color))
4729 ;; Specify effects (underline, overline, box, etc)
4730 (cond
4731 ((not (integerp effects))
4732 (ps-output "0 EF\n")
4733 (setq ps-current-effect 0))
4734 ((/= effects ps-current-effect)
4735 (ps-output (number-to-string effects) " EF\n")
4736 (setq ps-current-effect effects)))
4738 ;; Starting at the beginning of the specified region...
4739 (save-excursion
4740 (goto-char from)
4742 ;; ...break the region up into chunks separated by tabs, linefeeds,
4743 ;; pagefeeds, control characters, and plot each chunk.
4744 (while (< from to)
4745 (if (re-search-forward ps-control-or-escape-regexp to t)
4746 ;; region with some control characters or some multi-byte characters
4747 (let* ((match-point (match-beginning 0))
4748 (match (char-after match-point))
4749 (composition (find-composition from (1+ match-point))))
4750 (if composition
4751 (if (and (nth 2 composition)
4752 (<= (car composition) match-point))
4753 (progn
4754 (setq match-point (car composition)
4755 match 0)
4756 (goto-char (nth 1 composition)))
4757 (setq composition nil)))
4758 (when (< from match-point)
4759 (ps-mule-set-ascii-font)
4760 (ps-plot 'ps-basic-plot-string from match-point bg-color))
4761 (cond
4762 ((= match ?\t) ; tab
4763 (let ((linestart (line-beginning-position)))
4764 (forward-char -1)
4765 (setq from (+ linestart (current-column)))
4766 (when (re-search-forward "[ \t]+" to t)
4767 (ps-mule-set-ascii-font)
4768 (ps-plot 'ps-basic-plot-whitespace
4769 from (+ linestart (current-column))
4770 bg-color))))
4772 ((= match ?\n) ; newline
4773 (ps-next-line))
4775 ((= match ?\f) ; form feed
4776 ;; do not skip page if previous character is NEWLINE and
4777 ;; it is a beginning of page.
4778 (or (and (> match-point 1)
4779 (= (char-after (1- match-point)) ?\n)
4780 (= ps-height-remaining ps-print-height))
4781 (ps-next-page)))
4783 (composition ; a composite sequence
4784 (ps-plot 'ps-mule-plot-composition match-point (point) bg-color))
4786 ; characters from ^@ to ^_ and
4787 ((> match 255) ; a multi-byte character
4788 (let* ((charset (char-charset match))
4789 (composition (find-composition match-point to))
4790 (stop (if (nth 2 composition) (car composition) to)))
4791 (or (eq charset 'composition)
4792 (while (and (< (point) stop) (eq (charset-after) charset))
4793 (forward-char 1)))
4794 (ps-plot 'ps-mule-plot-string match-point (point) bg-color)))
4796 (t ; characters from 127 to 255
4797 (ps-control-character match)))
4798 (setq from (point)))
4799 ;; region without control characters nor multi-byte characters
4800 (ps-mule-set-ascii-font)
4801 (ps-plot 'ps-basic-plot-string from to bg-color)
4802 (setq from to)))))
4804 (defvar ps-string-control-codes
4805 (let ((table (make-vector 256 nil))
4806 (char ?\000))
4807 ;; control character
4808 (while (<= char ?\037)
4809 (aset table char (format "^%c" (+ char ?@)))
4810 (setq char (1+ char)))
4811 ;; printable character
4812 (while (< char ?\177)
4813 (aset table char (format "%c" char))
4814 (setq char (1+ char)))
4815 ;; DEL
4816 (aset table char "^?")
4817 ;; 8-bit character
4818 (while (<= (setq char (1+ char)) ?\377)
4819 (aset table char (format "\\%o" char)))
4820 table)
4821 "Vector used to map characters to a printable string.")
4823 (defun ps-control-character (char)
4824 (let* ((str (aref ps-string-control-codes char))
4825 (from (1- (point)))
4826 (len (length str))
4827 (to (+ from len))
4828 (char-width (ps-avg-char-width 'ps-font-for-text))
4829 (wrappoint (ps-find-wrappoint from to char-width)))
4830 (if (< (car wrappoint) to)
4831 (ps-continue-line))
4832 (setq ps-width-remaining (- ps-width-remaining (* len char-width)))
4833 (ps-mule-prepare-ascii-font str)
4834 (ps-output-string str)
4835 (ps-output " S\n")))
4837 (defun ps-color-scale (color)
4838 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
4839 (mapcar #'(lambda (value) (/ value ps-print-color-scale))
4840 (ps-color-values color)))
4843 (defun ps-xemacs-color-name (color)
4844 (if (color-specifier-p color)
4845 (color-name color)
4846 color))
4849 (cond ((eq ps-print-emacs-type 'emacs) ; emacs
4851 (defun ps-color-values (x-color)
4852 (if (fboundp 'x-color-values)
4853 (x-color-values x-color)
4854 (error "No available function to determine X color values.")))
4856 ; xemacs
4857 ; lucid
4858 (t ; epoch
4860 (or (find-coding-system 'raw-text-unix)
4861 (copy-coding-system 'no-conversion-unix 'raw-text-unix))
4863 (defun ps-color-values (x-color)
4864 (let ((color (ps-xemacs-color-name x-color)))
4865 (cond
4866 ((fboundp 'x-color-values)
4867 (x-color-values color))
4868 ((and (fboundp 'color-instance-rgb-components)
4869 (ps-color-device))
4870 (color-instance-rgb-components
4871 (if (color-instance-p x-color)
4872 x-color
4873 (make-color-instance color))))
4875 (error "No available function to determine X color values.")))))
4879 (defun ps-face-attributes (face)
4880 "Return face attribute vector.
4882 If FACE is not in `ps-print-face-extension-alist' or in
4883 `ps-print-face-alist', insert it on `ps-print-face-alist' and
4884 return the attribute vector.
4886 If FACE is not a valid face name, it is used default face."
4887 (cdr (or (assq face ps-print-face-extension-alist)
4888 (assq face ps-print-face-alist)
4889 (let* ((the-face (if (facep face) face 'default))
4890 (new-face (ps-screen-to-bit-face the-face)))
4891 (or (and (eq the-face 'default)
4892 (assq the-face ps-print-face-alist))
4893 (setq ps-print-face-alist (cons new-face ps-print-face-alist)))
4894 new-face))))
4897 (defun ps-face-background (face background)
4898 (and (or (eq ps-use-face-background t)
4899 (cond ((symbolp face)
4900 (memq face ps-use-face-background))
4901 ((listp face)
4902 (let (ok)
4903 (while face
4904 (if (memq (car face) ps-use-face-background)
4905 (setq face nil
4906 ok t)
4907 (setq face (cdr face))))
4908 ok))
4910 nil)
4912 background))
4915 (defun ps-face-attribute-list (face-or-list)
4916 (if (listp face-or-list)
4917 ;; list of faces
4918 (let ((effects 0)
4919 foreground background face-attr face)
4920 (while face-or-list
4921 (setq face (car face-or-list)
4922 face-or-list (cdr face-or-list)
4923 face-attr (ps-face-attributes face)
4924 effects (logior effects (aref face-attr 0)))
4925 (or foreground (setq foreground (aref face-attr 1)))
4926 (or background
4927 (setq background (ps-face-background face (aref face-attr 2)))))
4928 (vector effects foreground background))
4929 ;; simple face
4930 (ps-face-attributes face-or-list)))
4933 (defconst ps-font-type (vector nil 'bold 'italic 'bold-italic))
4936 (defun ps-plot-with-face (from to face)
4937 (cond
4938 ((null face) ; print text with null face
4939 (ps-plot-region from to 0))
4940 ((eq face 'emacs--invisible--face)) ; skip invisible text!!!
4941 (t ; otherwise, text has a valid face
4942 (let* ((face-bit (ps-face-attribute-list face))
4943 (effect (aref face-bit 0))
4944 (foreground (aref face-bit 1))
4945 (background (ps-face-background face (aref face-bit 2)))
4946 (fg-color (if (and ps-color-p foreground)
4947 (ps-color-scale foreground)
4948 ps-default-color))
4949 (bg-color (and ps-color-p background
4950 (ps-color-scale background))))
4951 (ps-plot-region
4952 from to
4953 (ps-font-number 'ps-font-for-text
4954 (or (aref ps-font-type (logand effect 3))
4955 face))
4956 fg-color bg-color (lsh effect -2)))))
4957 (goto-char to))
4960 (defun ps-xemacs-face-kind-p (face kind kind-regex)
4961 (let* ((frame-font (or (face-font-instance face)
4962 (face-font-instance 'default)))
4963 (kind-cons (and frame-font
4964 (assq kind
4965 (font-instance-properties frame-font))))
4966 (kind-spec (cdr-safe kind-cons))
4967 (case-fold-search t))
4968 (and kind-spec (string-match kind-regex kind-spec))))
4971 (cond ((eq ps-print-emacs-type 'emacs) ; emacs
4973 (defalias 'ps-face-foreground-name 'face-foreground)
4974 (defalias 'ps-face-background-name 'face-background)
4976 (defun ps-face-bold-p (face)
4977 (or (face-bold-p face)
4978 (memq face ps-bold-faces)))
4980 (defun ps-face-italic-p (face)
4981 (or (face-italic-p face)
4982 (memq face ps-italic-faces)))
4984 ; xemacs
4985 ; lucid
4986 (t ; epoch
4987 (defun ps-face-foreground-name (face)
4988 (ps-xemacs-color-name (face-foreground face)))
4990 (defun ps-face-background-name (face)
4991 (ps-xemacs-color-name (face-background face)))
4993 (defun ps-face-bold-p (face)
4994 (or (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold")
4995 (memq face ps-bold-faces))) ; Kludge-compatible
4997 (defun ps-face-italic-p (face)
4998 (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o")
4999 (ps-xemacs-face-kind-p face 'SLANT "i\\|o")
5000 (memq face ps-italic-faces))) ; Kludge-compatible
5004 (defun ps-face-underlined-p (face)
5005 (or (face-underline-p face)
5006 (memq face ps-underlined-faces)))
5009 ;; Ensure that face-list is fbound.
5010 (or (fboundp 'face-list) (defalias 'face-list 'list-faces))
5013 (defun ps-build-reference-face-lists ()
5014 ;; Ensure that face database is updated with faces on
5015 ;; `font-lock-face-attributes' (obsolete stuff)
5016 (ps-font-lock-face-attributes)
5017 ;; Now, rebuild reference face lists
5018 (setq ps-print-face-alist nil)
5019 (if ps-auto-font-detect
5020 (mapcar 'ps-map-face (face-list))
5021 (mapcar 'ps-set-face-bold ps-bold-faces)
5022 (mapcar 'ps-set-face-italic ps-italic-faces)
5023 (mapcar 'ps-set-face-underline ps-underlined-faces))
5024 (setq ps-build-face-reference nil))
5027 (defun ps-set-face-bold (face)
5028 (ps-set-face-attribute face 1))
5030 (defun ps-set-face-italic (face)
5031 (ps-set-face-attribute face 2))
5033 (defun ps-set-face-underline (face)
5034 (ps-set-face-attribute face 4))
5037 (defun ps-set-face-attribute (face effect)
5038 (let ((face-bit (cdr (ps-map-face face))))
5039 (aset face-bit 0 (logior (aref face-bit 0) effect))))
5042 (defun ps-map-face (face)
5043 (let* ((face-map (ps-screen-to-bit-face face))
5044 (ps-face-bit (cdr (assq (car face-map) ps-print-face-alist))))
5045 (if ps-face-bit
5046 ;; if face exists, merge both
5047 (let ((face-bit (cdr face-map)))
5048 (aset ps-face-bit 0 (logior (aref ps-face-bit 0) (aref face-bit 0)))
5049 (or (aref ps-face-bit 1) (aset ps-face-bit 1 (aref face-bit 1)))
5050 (or (aref ps-face-bit 2) (aset ps-face-bit 2 (aref face-bit 2))))
5051 ;; if face does not exist, insert it
5052 (setq ps-print-face-alist (cons face-map ps-print-face-alist)))
5053 face-map))
5056 (defun ps-screen-to-bit-face (face)
5057 (cons face
5058 (vector (logior (if (ps-face-bold-p face) 1 0) ; bold
5059 (if (ps-face-italic-p face) 2 0) ; italic
5060 (if (ps-face-underlined-p face) 4 0)) ; underline
5061 (ps-face-foreground-name face)
5062 (ps-face-background-name face))))
5065 (cond ((not (eq ps-print-emacs-type 'emacs))
5066 ; xemacs
5067 ; lucid
5068 ; epoch
5069 (defun ps-mapper (extent list)
5070 (nconc list (list (list (extent-start-position extent) 'push extent)
5071 (list (extent-end-position extent) 'pull extent)))
5072 nil)
5074 (defun ps-extent-sorter (a b)
5075 (< (extent-priority a) (extent-priority b)))
5079 (defun ps-print-ensure-fontified (start end)
5080 (and (boundp 'lazy-lock-mode) (symbol-value 'lazy-lock-mode)
5081 (lazy-lock-fontify-region start end)))
5083 (defun ps-generate-postscript-with-faces (from to)
5084 ;; Some initialization...
5085 (setq ps-current-effect 0)
5087 ;; Build the reference lists of faces if necessary.
5088 (when (or ps-always-build-face-reference
5089 ps-build-face-reference)
5090 (message "Collecting face information...")
5091 (ps-build-reference-face-lists))
5092 ;; Generate some PostScript.
5093 (save-restriction
5094 (narrow-to-region from to)
5095 (ps-print-ensure-fontified from to)
5096 (let ((face 'default)
5097 (position to))
5098 (cond
5099 ((memq ps-print-emacs-type '(xemacs lucid))
5100 ;; Build the list of extents...
5101 (let ((a (cons 'dummy nil))
5102 record type extent extent-list)
5103 (map-extents 'ps-mapper nil from to a)
5104 (setq a (sort (cdr a) 'car-less-than-car)
5105 extent-list nil)
5107 ;; Loop through the extents...
5108 (while a
5109 (setq record (car a)
5111 position (car record)
5112 record (cdr record)
5114 type (car record)
5115 record (cdr record)
5117 extent (car record))
5119 ;; Plot up to this record.
5120 ;; XEmacs 19.12: for some reason, we're getting into a
5121 ;; situation in which some of the records have
5122 ;; positions less than 'from'. Since we've narrowed
5123 ;; the buffer, this'll generate errors. This is a
5124 ;; hack, but don't call ps-plot-with-face unless from >
5125 ;; point-min.
5126 (and (>= from (point-min)) (<= position (point-max))
5127 (ps-plot-with-face from position face))
5129 (cond
5130 ((eq type 'push)
5131 (and (extent-face extent)
5132 (setq extent-list (sort (cons extent extent-list)
5133 'ps-extent-sorter))))
5135 ((eq type 'pull)
5136 (setq extent-list (sort (delq extent extent-list)
5137 'ps-extent-sorter))))
5139 (setq face (if extent-list
5140 (extent-face (car extent-list))
5141 'default)
5142 from position
5143 a (cdr a)))))
5145 ((eq ps-print-emacs-type 'emacs)
5146 (let ((property-change from)
5147 (overlay-change from)
5148 (save-buffer-invisibility-spec buffer-invisibility-spec)
5149 (buffer-invisibility-spec nil))
5150 (while (< from to)
5151 (and (< property-change to) ; Don't search for property change
5152 ; unless previous search succeeded.
5153 (setq property-change (next-property-change from nil to)))
5154 (and (< overlay-change to) ; Don't search for overlay change
5155 ; unless previous search succeeded.
5156 (setq overlay-change (min (next-overlay-change from) to)))
5157 (setq position (min property-change overlay-change))
5158 ;; The code below is not quite correct,
5159 ;; because a non-nil overlay invisible property
5160 ;; which is inactive according to the current value
5161 ;; of buffer-invisibility-spec nonetheless overrides
5162 ;; a face text property.
5163 (setq face
5164 (cond ((let ((prop (get-text-property from 'invisible)))
5165 ;; Decide whether this invisible property
5166 ;; really makes the text invisible.
5167 (if (eq save-buffer-invisibility-spec t)
5168 (not (null prop))
5169 (or (memq prop save-buffer-invisibility-spec)
5170 (assq prop save-buffer-invisibility-spec))))
5171 'emacs--invisible--face)
5172 ((get-text-property from 'face))
5173 (t 'default)))
5174 (let ((overlays (overlays-at from))
5175 (face-priority -1)) ; text-property
5176 (while (and overlays
5177 (not (eq face 'emacs--invisible--face)))
5178 (let* ((overlay (car overlays))
5179 (overlay-invisible (overlay-get overlay 'invisible))
5180 (overlay-priority (or (overlay-get overlay 'priority)
5181 0)))
5182 (and (> overlay-priority face-priority)
5183 (setq face
5184 (cond ((if (eq save-buffer-invisibility-spec t)
5185 (not (null overlay-invisible))
5186 (or (memq overlay-invisible
5187 save-buffer-invisibility-spec)
5188 (assq overlay-invisible
5189 save-buffer-invisibility-spec)))
5190 'emacs--invisible--face)
5191 ((overlay-get overlay 'face))
5192 (t face))
5193 face-priority overlay-priority)))
5194 (setq overlays (cdr overlays))))
5195 ;; Plot up to this record.
5196 (ps-plot-with-face from position face)
5197 (setq from position)))))
5198 (ps-plot-with-face from to face))))
5200 (defun ps-generate-postscript (from to)
5201 (ps-plot-region from to 0 nil))
5203 (defun ps-generate (buffer from to genfunc)
5204 (save-excursion
5205 (let ((from (min to from))
5206 (to (max to from))
5207 ;; This avoids trouble if chars with read-only properties
5208 ;; are copied into ps-spool-buffer.
5209 (inhibit-read-only t))
5210 (save-restriction
5211 (narrow-to-region from to)
5212 (and ps-razzle-dazzle
5213 (message "Formatting...%3d%%" (setq ps-razchunk 0)))
5214 (setq ps-source-buffer buffer
5215 ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
5216 (ps-init-output-queue)
5217 (let (safe-marker completed-safely needs-begin-file)
5218 (unwind-protect
5219 (progn
5220 (set-buffer ps-spool-buffer)
5221 (set-buffer-multibyte nil)
5223 ;; Get a marker and make it point to the current end of the
5224 ;; buffer, If an error occurs, we'll delete everything from
5225 ;; the end of this marker onwards.
5226 (setq safe-marker (make-marker))
5227 (set-marker safe-marker (point-max))
5229 (goto-char (point-min))
5230 (or (looking-at (regexp-quote ps-adobe-tag))
5231 (setq needs-begin-file t))
5232 (save-excursion
5233 (set-buffer ps-source-buffer)
5234 (ps-begin-job)
5235 (when needs-begin-file
5236 (ps-begin-file)
5237 (ps-mule-initialize))
5238 (ps-mule-begin-job from to)
5239 (ps-selected-pages)
5240 (ps-begin-page))
5241 (set-buffer ps-source-buffer)
5242 (funcall genfunc from to)
5243 (ps-end-page)
5245 (ps-end-file needs-begin-file)
5246 (ps-end-job)
5248 ;; Setting this variable tells the unwind form that the
5249 ;; the PostScript was generated without error.
5250 (setq completed-safely t))
5252 ;; Unwind form: If some bad mojo occurred while generating
5253 ;; PostScript, delete all the PostScript that was generated.
5254 ;; This protects the previously spooled files from getting
5255 ;; corrupted.
5256 (and (markerp safe-marker) (not completed-safely)
5257 (progn
5258 (set-buffer ps-spool-buffer)
5259 (delete-region (marker-position safe-marker) (point-max))))))
5261 (and ps-razzle-dazzle (message "Formatting...done"))))))
5264 (defun ps-end-job ()
5265 (ps-flush-output)
5266 (let ((total-lines (cdr ps-printing-region))
5267 (total-pages (if ps-print-only-one-header
5268 (ps-page-number)
5269 ps-page-count))
5270 case-fold-search)
5271 (set-buffer ps-spool-buffer)
5272 ;; Back to the PS output buffer to set the page count
5273 (goto-char (point-min))
5274 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t)
5275 (replace-match (format "/Lines %d def\n/PageCount %d def"
5276 total-lines total-pages) t)))
5277 ;; selected pages
5278 (setq ps-selected-pages nil))
5281 (defvar ps-printer-name-option
5282 (cond (ps-windows-system
5283 "-P")
5284 (ps-lp-system
5285 "-d")
5287 "-P" )))
5290 ;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
5291 (defun ps-do-despool (filename)
5292 (if (or (not (boundp 'ps-spool-buffer))
5293 (not (symbol-value 'ps-spool-buffer)))
5294 (message "No spooled PostScript to print")
5295 (if filename
5296 (save-excursion
5297 (and ps-razzle-dazzle (message "Saving..."))
5298 (set-buffer ps-spool-buffer)
5299 (setq filename (expand-file-name filename))
5300 (let ((coding-system-for-write 'raw-text-unix))
5301 (write-region (point-min) (point-max) filename))
5302 (and ps-razzle-dazzle (message "Wrote %s" filename)))
5303 ;; Else, spool to the printer
5304 (and ps-razzle-dazzle (message "Printing..."))
5305 (save-excursion
5306 (set-buffer ps-spool-buffer)
5307 (let* ((coding-system-for-write 'raw-text-unix)
5308 (ps-printer-name (or ps-printer-name
5309 (and (boundp 'printer-name)
5310 printer-name)))
5311 (ps-lpr-switches
5312 (append (and (stringp ps-printer-name)
5313 (list (concat ps-printer-name-option
5314 ps-printer-name)))
5315 ps-lpr-switches)))
5316 (apply (or ps-print-region-function 'call-process-region)
5317 (point-min) (point-max) ps-lpr-command nil
5318 (and (fboundp 'start-process) 0)
5320 (ps-flatten-list ; dynamic evaluation
5321 (mapcar 'ps-eval-switch ps-lpr-switches)))))
5322 (and ps-razzle-dazzle (message "Printing...done")))
5323 (kill-buffer ps-spool-buffer)))
5325 ;; Dynamic evaluation
5326 (defun ps-eval-switch (arg)
5327 (cond ((stringp arg) arg)
5328 ((functionp arg) (apply arg nil))
5329 ((symbolp arg) (symbol-value arg))
5330 ((consp arg) (apply (car arg) (cdr arg)))
5331 (t nil)))
5333 ;; `ps-flatten-list' is defined here (copied from "message.el" and
5334 ;; enhanced to handle dotted pairs as well) until we can get some
5335 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
5337 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
5338 ;; => (a b c d e f g h i j)
5340 (defun ps-flatten-list (&rest list)
5341 (ps-flatten-list-1 list))
5343 (defun ps-flatten-list-1 (list)
5344 (cond ((null list) nil)
5345 ((consp list) (append (ps-flatten-list-1 (car list))
5346 (ps-flatten-list-1 (cdr list))))
5347 (t (list list))))
5349 (defun ps-kill-emacs-check ()
5350 (let (ps-buffer)
5351 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
5352 (buffer-modified-p ps-buffer)
5353 (y-or-n-p "Unprinted PostScript waiting; print now? ")
5354 (ps-despool))
5355 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
5356 (buffer-modified-p ps-buffer)
5357 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
5358 (error "Unprinted PostScript"))))
5360 (cond ((fboundp 'add-hook)
5361 (funcall 'add-hook 'kill-emacs-hook 'ps-kill-emacs-check))
5362 (kill-emacs-hook
5363 (message "Won't override existing `kill-emacs-hook'"))
5365 (setq kill-emacs-hook 'ps-kill-emacs-check)))
5368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5369 ;;; Sample Setup Code:
5372 ;; This stuff is for anybody that's brave enough to look this far,
5373 ;; and able to figure out how to use it. It isn't really part of
5374 ;; ps-print, but I'll leave it here in hopes it might be useful:
5376 ;; WARNING!!! The following code is *sample* code only.
5377 ;; Don't use it unless you understand what it does!
5379 (defmacro ps-prsc ()
5380 `(if (eq ps-print-emacs-type 'emacs) [f22] 'f22))
5381 (defmacro ps-c-prsc ()
5382 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
5383 (defmacro ps-s-prsc ()
5384 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
5386 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
5387 ;; `ps-left-headers' specially for mail messages.
5388 (defun ps-rmail-mode-hook ()
5389 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
5390 (setq ps-header-lines 3
5391 ps-left-header
5392 ;; The left headers will display the message's subject, its
5393 ;; author, and the name of the folder it was in.
5394 '(ps-article-subject ps-article-author buffer-name)))
5396 ;; See `ps-gnus-print-article-from-summary'. This function does the
5397 ;; same thing for rmail.
5398 (defun ps-rmail-print-message-from-summary ()
5399 (interactive)
5400 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
5402 ;; Used in `ps-rmail-print-article-from-summary',
5403 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
5404 (defun ps-print-message-from-summary (summary-buffer summary-default)
5405 (let ((ps-buf (or (and (boundp summary-buffer)
5406 (symbol-value summary-buffer))
5407 summary-default)))
5408 (and (get-buffer ps-buf)
5409 (save-excursion
5410 (set-buffer ps-buf)
5411 (ps-spool-buffer-with-faces)))))
5413 ;; Look in an article or mail message for the Subject: line. To be
5414 ;; placed in `ps-left-headers'.
5415 (defun ps-article-subject ()
5416 (save-excursion
5417 (goto-char (point-min))
5418 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
5419 (buffer-substring (match-beginning 1) (match-end 1))
5420 "Subject ???")))
5422 ;; Look in an article or mail message for the From: line. Sorta-kinda
5423 ;; understands RFC-822 addresses and can pull the real name out where
5424 ;; it's provided. To be placed in `ps-left-headers'.
5425 (defun ps-article-author ()
5426 (save-excursion
5427 (goto-char (point-min))
5428 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
5429 (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
5430 (cond
5432 ;; Try first to match addresses that look like
5433 ;; thompson@wg2.waii.com (Jim Thompson)
5434 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
5435 (substring fromstring (match-beginning 1) (match-end 1)))
5437 ;; Next try to match addresses that look like
5438 ;; Jim Thompson <thompson@wg2.waii.com> or
5439 ;; "Jim Thompson" <thompson@wg2.waii.com>
5440 ((string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring)
5441 (substring fromstring (match-beginning 2) (match-end 2)))
5443 ;; Couldn't find a real name -- show the address instead.
5444 (t fromstring)))
5445 "From ???")))
5447 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
5448 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
5449 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
5450 ;; buffer enters that mode, so it would only work for the first time
5451 ;; we ran gnus. The second time, this hook wouldn't get set up. The
5452 ;; only alternative is `gnus-article-prepare-hook'.
5453 (defun ps-gnus-article-prepare-hook ()
5454 (setq ps-header-lines 3
5455 ps-left-header
5456 ;; The left headers will display the article's subject, its
5457 ;; author, and the newsgroup it was in.
5458 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
5460 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
5461 ;; `ps-left-headers' specially for mail messages.
5462 (defun ps-vm-mode-hook ()
5463 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
5464 (setq ps-header-lines 3
5465 ps-left-header
5466 ;; The left headers will display the message's subject, its
5467 ;; author, and the name of the folder it was in.
5468 '(ps-article-subject ps-article-author buffer-name)))
5470 ;; Every now and then I forget to switch from the *Summary* buffer to
5471 ;; the *Article* before hitting prsc, and a nicely formatted list of
5472 ;; article subjects shows up at the printer. This function, bound to
5473 ;; prsc for the gnus *Summary* buffer means I don't have to switch
5474 ;; buffers first.
5475 ;; sb: Updated for Gnus 5.
5476 (defun ps-gnus-print-article-from-summary ()
5477 (interactive)
5478 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
5480 ;; See `ps-gnus-print-article-from-summary'. This function does the
5481 ;; same thing for vm.
5482 (defun ps-vm-print-message-from-summary ()
5483 (interactive)
5484 (ps-print-message-from-summary 'vm-mail-buffer ""))
5486 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
5487 ;; prsc.
5488 (defun ps-gnus-summary-setup ()
5489 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
5491 ;; Look in an article or mail message for the Subject: line. To be
5492 ;; placed in `ps-left-headers'.
5493 (defun ps-info-file ()
5494 (save-excursion
5495 (goto-char (point-min))
5496 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
5497 (buffer-substring (match-beginning 1) (match-end 1))
5498 "File ???")))
5500 ;; Look in an article or mail message for the Subject: line. To be
5501 ;; placed in `ps-left-headers'.
5502 (defun ps-info-node ()
5503 (save-excursion
5504 (goto-char (point-min))
5505 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
5506 (buffer-substring (match-beginning 1) (match-end 1))
5507 "Node ???")))
5509 (defun ps-info-mode-hook ()
5510 (setq ps-left-header
5511 ;; The left headers will display the node name and file name.
5512 '(ps-info-node ps-info-file)))
5514 ;; WARNING! The following function is a *sample* only, and is *not*
5515 ;; meant to be used as a whole unless you understand what the effects
5516 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
5517 ;; I'd be very surprised if it was useful to *anybody*, without
5518 ;; modification.)
5520 (defun ps-jts-ps-setup ()
5521 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
5522 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
5523 (global-set-key (ps-c-prsc) 'ps-despool)
5524 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
5525 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
5526 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
5527 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
5528 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
5529 (setq ps-spool-duplex t
5530 ps-print-color-p nil
5531 ps-lpr-command "lpr"
5532 ps-lpr-switches '("-Jjct,duplex_long"))
5533 'ps-jts-ps-setup)
5535 ;; WARNING! The following function is a *sample* only, and is *not*
5536 ;; meant to be used as a whole unless it corresponds to your needs.
5537 ;; (In fact, this is a copy of Jack's setup for ps-print --
5538 ;; I would not be that surprised if it was useful to *anybody*,
5539 ;; without modification.)
5541 (defun ps-jack-setup ()
5542 (setq ps-print-color-p nil
5543 ps-lpr-command "lpr"
5544 ps-lpr-switches nil
5546 ps-paper-type 'a4
5547 ps-landscape-mode t
5548 ps-number-of-columns 2
5550 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5551 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5552 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
5553 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5554 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5555 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
5556 ps-header-line-pad .15
5557 ps-print-header t
5558 ps-print-header-frame t
5559 ps-header-lines 2
5560 ps-show-n-of-n t
5561 ps-spool-duplex nil
5563 ps-font-family 'Courier
5564 ps-font-size 5.5
5565 ps-header-font-family 'Helvetica
5566 ps-header-font-size 6
5567 ps-header-title-font-size 8)
5568 'ps-jack-setup)
5571 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5572 ;; To make this file smaller, some commands go in a separate file.
5573 ;; But autoload them here to make the separation invisible.
5575 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
5576 "Setup special ASCII font for STRING.
5577 STRING should contain only ASCII characters.")
5579 (autoload 'ps-mule-set-ascii-font "ps-mule"
5580 "Adjust current font if current charset is not ASCII.")
5582 (autoload 'ps-mule-plot-string "ps-mule"
5583 "Generate PostScript code for ploting characters in the region FROM and TO.
5585 It is assumed that all characters in this region belong to the same charset.
5587 Optional argument BG-COLOR specifies background color.
5589 Returns the value:
5591 (ENDPOS . RUN-WIDTH)
5593 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
5594 the sequence.")
5596 (autoload 'ps-mule-initialize "ps-mule"
5597 "Initialize global data for printing multi-byte characters.")
5599 (autoload 'ps-mule-begin-job "ps-mule"
5600 "Start printing job for multi-byte chars between FROM and TO.
5601 This checks if all multi-byte characters in the region are printable or not.")
5603 (autoload 'ps-mule-begin-page "ps-mule"
5604 "Initialize multi-byte charset for printing current page.")
5607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5609 (provide 'ps-print)
5611 ;;; ps-print.el ends here