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