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