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