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