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