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