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