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