1 ;;; ps-print.el --- Print text from the buffer as PostScript
3 ;; Copyright (C) 1993-2000 Free Software Foundation, Inc.
5 ;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
6 ;; Author: Jacques Duthen (was <duthen@cegelec-red.fr>)
7 ;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
8 ;; Author: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
9 ;; Maintainer: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
10 ;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
11 ;; Keywords: wp, print, PostScript
12 ;; Time-stamp: <2000/06/05 14:40:03 vinicius>
15 (defconst ps-print-version
"5.2.2"
16 "ps-print.el, v 5.2.2 <2000/06/05 vinicius>
18 Vinicius's last change version -- this file may have been edited as part of
19 Emacs without changes to the version number. When reporting bugs, please also
20 report the version of Emacs, if any, that ps-print was distributed with.
22 Please send all bug fixes and enhancements to
23 Vinicius Jose Latorre <vinicius@cpqd.com.br>.
26 ;; This file is part of GNU Emacs.
28 ;; GNU Emacs is free software; you can redistribute it and/or modify
29 ;; it under the terms of the GNU General Public License as published by
30 ;; the Free Software Foundation; either version 2, or (at your option)
33 ;; GNU Emacs is distributed in the hope that it will be useful,
34 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 ;; GNU General Public License for more details.
38 ;; You should have received a copy of the GNU General Public License
39 ;; along with GNU Emacs; see the file COPYING. If not, write to the
40 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41 ;; Boston, MA 02111-1307, USA.
45 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
50 ;; This package provides printing of Emacs buffers on PostScript printers;
51 ;; the buffer's bold and italic text attributes are preserved in the printer
52 ;; output. ps-print is intended for use with Emacs or Lucid Emacs, together
53 ;; with a fontifying package such as font-lock or hilit.
55 ;; ps-print uses the same face attributes defined through font-lock or hilit
56 ;; to print a PostScript file, but some faces are better seeing on the screen
57 ;; than on paper, specially when you have a black/white PostScript printer.
59 ;; ps-print allows a remap of face to another one that it is better to print,
60 ;; for example, the face font-lock-comment-face (if you are using font-lock)
61 ;; could have bold or italic attribute when printing, besides foreground color.
62 ;; This remap improves printing look (see How Ps-Print Maps Faces).
68 ;; ps-print provides eight commands for generating PostScript images
72 ;; ps-print-buffer-with-faces
74 ;; ps-print-region-with-faces
76 ;; ps-spool-buffer-with-faces
78 ;; ps-spool-region-with-faces
80 ;; These commands all perform essentially the same function: they
81 ;; generate PostScript images suitable for printing on a PostScript
82 ;; printer or displaying with GhostScript. These commands are
83 ;; collectively referred to as "ps-print- commands".
85 ;; The word "print" or "spool" in the command name determines when the
86 ;; PostScript image is sent to the printer:
88 ;; print - The PostScript image is immediately sent to the
91 ;; spool - The PostScript image is saved temporarily in an
92 ;; Emacs buffer. Many images may be spooled locally
93 ;; before printing them. To send the spooled images
94 ;; to the printer, use the command `ps-despool'.
96 ;; The spooling mechanism was designed for printing lots of small
97 ;; files (mail messages or netnews articles) to save paper that would
98 ;; otherwise be wasted on banner pages, and to make it easier to find
99 ;; your output at the printer (it's easier to pick up one 50-page
100 ;; printout than to find 50 single-page printouts).
102 ;; ps-print has a hook in the `kill-emacs-hook' so that you won't
103 ;; accidentally quit from Emacs while you have unprinted PostScript
104 ;; waiting in the spool buffer. If you do attempt to exit with
105 ;; spooled PostScript, you'll be asked if you want to print it, and if
106 ;; you decline, you'll be asked to confirm the exit; this is modeled
107 ;; on the confirmation that Emacs uses for modified buffers.
109 ;; The word "buffer" or "region" in the command name determines how
110 ;; much of the buffer is printed:
112 ;; buffer - Print the entire buffer.
114 ;; region - Print just the current region.
116 ;; The -with-faces suffix on the command name means that the command
117 ;; will include font, color, and underline information in the
118 ;; PostScript image, so the printed image can look as pretty as the
119 ;; buffer. The ps-print- commands without the -with-faces suffix
120 ;; don't include font, color, or underline information; images printed
121 ;; with these commands aren't as pretty, but are faster to generate.
123 ;; Two ps-print- command examples:
125 ;; ps-print-buffer - print the entire buffer,
126 ;; without font, color, or
127 ;; underline information, and
128 ;; send it immediately to the
131 ;; ps-spool-region-with-faces - print just the current region;
132 ;; include font, color, and
133 ;; underline information, and
134 ;; spool the image in Emacs to
135 ;; send to the printer later.
141 ;; To print your buffer, type
143 ;; M-x ps-print-buffer
145 ;; or substitute one of the other seven ps-print- commands. The
146 ;; command will generate the PostScript image and print or spool it as
147 ;; specified. By giving the command a prefix argument
149 ;; C-u M-x ps-print-buffer
151 ;; it will save the PostScript image to a file instead of sending it
152 ;; to the printer; you will be prompted for the name of the file to
153 ;; save the image to. The prefix argument is ignored by the commands
154 ;; that spool their images, but you may save the spooled images to a
155 ;; file by giving a prefix argument to `ps-despool':
157 ;; C-u M-x ps-despool
159 ;; When invoked this way, `ps-despool' will prompt you for the name of
160 ;; the file to save to.
162 ;; Any of the `ps-print-' commands can be bound to keys; I recommend
163 ;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
164 ;; and `ps-despool'. Here are the bindings I use on my Sun 4 keyboard:
166 ;; (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
167 ;; (global-set-key '(shift f22) 'ps-spool-region-with-faces)
168 ;; (global-set-key '(control f22) 'ps-despool)
171 ;; The Printer Interface
172 ;; ---------------------
174 ;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
175 ;; command is used to send the PostScript images to the printer, and
176 ;; what arguments to give the command. These are analogous to
177 ;; `lpr-command' and `lpr-switches'.
179 ;; Make sure that they contain appropriate values for your system;
180 ;; see the usage notes below and the documentation of these variables.
182 ;; The variable `ps-printer-name' determines the name of a local printer for
183 ;; printing PostScript files.
185 ;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
186 ;; from the variables `lpr-command' and `lpr-switches'. If you have
187 ;; `lpr-command' set to invoke a pretty-printer such as `enscript',
188 ;; then ps-print won't work properly. `ps-lpr-command' must name
189 ;; a program that does not format the files it prints.
190 ;; `ps-printer-name' takes its initial value from the variable
193 ;; The variable `ps-print-region-function' specifies a function to print the
194 ;; region on a PostScript printer.
195 ;; See definition of `call-process-region' for calling conventions. The fourth
196 ;; and the sixth arguments are both nil.
198 ;; The variable `ps-manual-feed' indicates if the printer will manually feed
199 ;; paper. If it's nil, automatic feeding takes place. If it's non-nil, manual
200 ;; feeding takes place. The default is nil (automatic feeding).
202 ;; If you're using Emacs for Windows 95/98/NT or MS-DOS, don't forget to
203 ;; customize the following variables: `ps-printer-name', `ps-lpr-command',
204 ;; `ps-lpr-switches' and `ps-spool-config'. See these variables documentation
205 ;; in the code or by typing, for example, C-h v ps-printer-name RET.
211 ;; All dimensions are floats in PostScript points.
212 ;; 1 inch == 2.54 cm == 72 points
213 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
215 ;; The variable `ps-paper-type' determines the size of paper ps-print formats
216 ;; for; it should contain one of the symbols: `a4' `a3' `letter' `legal'
217 ;; `letter-small' `tabloid' `ledger' `statement' `executive' `a4small' `b4'
220 ;; If variable `ps-warn-paper-type' is nil, it's *not* given an error if
221 ;; PostScript printer doesn't have a paper with the size indicated by
222 ;; `ps-paper-type', instead it uses the default paper size. If variable
223 ;; `ps-warn-paper-type' is non-nil, it's given an error if PostScript printer
224 ;; doesn't have a paper with the size indicated by `ps-paper-type'. It's used
225 ;; when `ps-spool-config' is set to `setpagedevice' (see section Duplex
226 ;; Printers). The default value is non-nil (it gives an error).
228 ;; The variable `ps-landscape-mode' determines the orientation of the printing
229 ;; on the page: nil means `portrait' mode, non-nil means `landscape' mode.
230 ;; There is no oblique mode yet, though this is easy to do in ps.
232 ;; In landscape mode, the text is NOT scaled: you may print 70 lines in portrait
233 ;; mode and only 50 lines in landscape mode. The margins represent margins in
234 ;; the printed paper: the top margin is the margin between the top of the page
235 ;; and the printed header, whatever the orientation is.
237 ;; The variable `ps-number-of-columns' determines the number of columns both in
238 ;; landscape and portrait mode.
240 ;; - (the standard) one column portrait mode.
241 ;; - (my favorite) two columns landscape mode (which spares trees).
243 ;; - one column landscape mode for files with very long lines.
244 ;; - multi-column portrait or landscape mode.
246 ;; The variable `ps-print-upside-down' determines other orientation for printing
247 ;; page: nil means `normal' printing, non-nil means `upside-down' printing. The
248 ;; default value is nil (`normal' printing).
250 ;; The `upside-down' orientation can be used in portrait or landscape mode.
256 ;; The horizontal layout is determined by the variables
257 ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
260 ;; ------------------------------------------
262 ;; | lm | text | ic | text | ic | text | rm |
264 ;; ------------------------------------------
266 ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
267 ;; Usually, lm = rm > 0 and ic = lm
268 ;; If (ic < 0), the text of adjacent columns can overlap.
274 ;; The vertical layout is determined by the variables
275 ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
278 ;; |--------| |--------|
280 ;; |--------| |--------|
284 ;; |--------| or | text |
288 ;; |--------| |--------|
290 ;; |--------| |--------|
292 ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
293 ;; The margins represent margins in the printed paper:
294 ;; the top margin is the margin between the top of the page
295 ;; and the printed header, whatever the orientation is.
301 ;; ps-print can print headers at the top of each column or at the top
302 ;; of each page; the default headers contain the following four items:
303 ;; on the left, the name of the buffer and, if the buffer is visiting
304 ;; a file, the file's directory; on the right, the page number and
305 ;; date of printing. The default headers look something like this:
308 ;; /home/jct/emacs-lisp/ps/new 94/12/31
310 ;; When printing on duplex printers, left and right are reversed so
311 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
313 ;; Headers are configurable:
314 ;; To turn them off completely, set `ps-print-header' to nil.
315 ;; To turn off the header's gaudy framing box,
316 ;; set `ps-print-header-frame' to nil.
318 ;; To print only one header at the top of each page,
319 ;; set `ps-print-only-one-header' to t.
321 ;; To switch headers, set `ps-switch-header' to:
323 ;; nil Never switch headers.
325 ;; t Always switch headers.
327 ;; duplex Switch headers only when duplexing is on, that is, when
328 ;; `ps-spool-duplex' is non-nil (see Duplex Printers).
330 ;; Any other value is treated as t. The default value is `duplex'.
332 ;; The font family and size of text in the header are determined
333 ;; by the variables `ps-header-font-family', `ps-header-font-size' and
334 ;; `ps-header-title-font-size' (see below).
336 ;; The variable `ps-header-line-pad' determines the portion of a header
337 ;; title line height to insert between the header frame and the text
338 ;; it contains, both in the vertical and horizontal directions:
339 ;; .5 means half a line.
341 ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
342 ;; to omit the total page count and just print the page number,
343 ;; set `ps-show-n-of-n' to nil.
345 ;; The amount of information in the header can be changed by changing
346 ;; the number of lines. To show less, set `ps-header-lines' to 1, and
347 ;; the header will show only the buffer name and page number. To show
348 ;; more, set `ps-header-lines' to 3, and the header will show the time of
349 ;; printing below the date.
351 ;; To change the content of the headers, change the variables
352 ;; `ps-left-header' and `ps-right-header'.
353 ;; These variables are lists, specifying top-to-bottom the text
354 ;; to display on the left or right side of the header.
355 ;; Each element of the list should be a string or a symbol.
356 ;; Strings are inserted directly into the PostScript arrays,
357 ;; and should contain the PostScript string delimiters '(' and ')'.
359 ;; Symbols in the header format lists can either represent functions
360 ;; or variables. Functions are called, and should return a string to
361 ;; show in the header. Variables should contain strings to display in
362 ;; the header. In either case, function or variable, the PostScript
363 ;; string delimiters are added by ps-print, and should not be part of
364 ;; the returned value.
366 ;; Here's an example: say we want the left header to display the text
372 ;; where we have a function to return "Moe"
374 ;; (defun moe-func ()
377 ;; a variable specifying "Larry"
379 ;; (setq larry-var "Larry")
381 ;; and a literal for "Curly". Here's how `ps-left-header' should be
384 ;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
386 ;; Note that Curly has the PostScript string delimiters inside his
387 ;; quotes -- those aren't misplaced lisp delimiters!
389 ;; Without them, PostScript would attempt to call the undefined
390 ;; function Curly, which would result in a PostScript error.
392 ;; Since most printers don't report PostScript errors except by
393 ;; aborting the print job, this kind of error can be hard to track down.
395 ;; Consider yourself warned!
398 ;; PostScript Prologue Header
399 ;; --------------------------
401 ;; It is possible to add PostScript prologue header comments besides that
402 ;; ps-print generates by setting the variable `ps-print-prologue-header'.
404 ;; `ps-print-prologue-header' may be a string or a symbol function which returns
405 ;; a string. Note that this string is inserted on PostScript prologue header
406 ;; section which is used to define some document characteristic through
407 ;; PostScript special comments, like "%%Requirements: jog\n".
409 ;; By default `ps-print-prologue-header' is nil.
411 ;; ps-print always inserts the %%Requirements: comment, so if you need to insert
412 ;; more requirements put them first in `ps-print-prologue-header' using the
413 ;; "%%+" comment. For example, if you need to set numcopies to 3 and jog on
414 ;; requirements and set %%LanguageLevel: to 2, do:
416 ;; (setq ps-print-prologue-header
417 ;; "%%+ numcopies(3) jog\n%%LanguageLevel: 2\n")
419 ;; The duplex requirement is inserted by ps-print (see section Duplex Printers).
421 ;; Do not forget to terminate the string with "\n".
423 ;; For more information about PostScript document comments, see:
424 ;; PostScript Language Reference Manual (2nd edition)
425 ;; Adobe Systems Incorporated
426 ;; Appendix G: Document Structuring Conventions -- Version 3.0
428 ;; It is also possible to add an user defined PostScript prologue code before
429 ;; all generated prologue code by setting the variable
430 ;; `ps-user-defined-prologue'.
432 ;; `ps-user-defined-prologue' may be a string or a symbol function which returns
433 ;; a string. Note that this string is inserted after `ps-adobe-tag' and
434 ;; PostScript prologue comments, and before ps-print PostScript prologue code
435 ;; section. That is, this string is inserted after error handler initialization
436 ;; and before ps-print settings.
438 ;; By default `ps-user-defined-prologue' is nil.
440 ;; It's recommended to initiate and terminate the string with "\n".
442 ;; It's strongly recommended only insert PostScript code and/or comments
443 ;; specific for your printing system particularities. For example, some special
444 ;; initialization that only your printing system needs.
446 ;; Do not insert code for duplex printing, n-up printing or error handler,
447 ;; ps-print handles this in a suitable way.
449 ;; For more information about PostScript, see:
450 ;; PostScript Language Reference Manual (2nd edition)
451 ;; Adobe Systems Incorporated
454 ;; PostScript Error Handler
455 ;; ------------------------
457 ;; ps-print instruments generated PostScript code with an error handler.
459 ;; The variable `ps-error-handler-message' specifies where the error handler
460 ;; message should be sent.
464 ;; none catch the error and *DON'T* send any message.
466 ;; paper catch the error and print on paper the error message.
467 ;; This is the default value.
469 ;; system catch the error and send back the error message to
470 ;; printing system. This is useful only if printing system
471 ;; send back an email reporting the error, or if there is
472 ;; some other alternative way to report back the error from
473 ;; the system to you.
475 ;; paper-and-system catch the error, print on paper the error message and
476 ;; send back the error message to printing system.
478 ;; Any other value is treated as `paper'.
484 ;; If you have a duplex-capable printer (one that prints both sides of the
485 ;; paper), set `ps-spool-duplex' to t.
486 ;; ps-print will insert blank pages to make sure each buffer starts on the
487 ;; correct side of the paper.
489 ;; The variable `ps-spool-config' specifies who is the responsable for setting
490 ;; duplex and page size switches. Valid values are:
492 ;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
493 ;; Don't forget to set `ps-lpr-switches' to select duplex
494 ;; printing for your printer.
496 ;; setpagedevice duplex and page size are configured by ps-print using the
497 ;; setpagedevice PostScript operator.
499 ;; nil duplex and page size are configured by ps-print *not* using
500 ;; the setpagedevice PostScript operator.
502 ;; Any other value is treated as nil.
504 ;; The default value is `lpr-switches'.
506 ;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
507 ;; viewing file generated using landscape. Also on some printers,
508 ;; setpagedevice affects zebra stripes; on other printers,
509 ;; setpagedevice affects the left margin.
510 ;; Besides all that, if your printer does not have the paper size
511 ;; specified by setpagedevice, your printing will be aborted.
512 ;; So, if you need to use setpagedevice, set `ps-spool-config' to
513 ;; `setpagedevice', generate a test file and send it to your printer;
514 ;; if the printed file isn't ok, set `ps-spool-config' to nil.
516 ;; The variable `ps-spool-tumble' specifies how the page images on opposite
517 ;; sides of a sheet are oriented with respect to each other. If
518 ;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
519 ;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
520 ;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
521 ;; The default value is nil.
523 ;; Some printer system prints a header page and forces the first page be printed
524 ;; on header page back, when using duplex. If your printer system has this
525 ;; behavior, set variable `ps-banner-page-when-duplexing' to t.
527 ;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
528 ;; skipped. It's like the very first character of buffer (or region) is ^L
531 ;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
538 ;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
539 ;; paper. The value specified must be between 1 and 100. The default is 1.
541 ;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
542 ;; to a high value (for example, 23). If this happens, set a lower value.
544 ;; The variable `ps-n-up-margin' specifies the margin in points between the
545 ;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
548 ;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
551 ;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
552 ;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
553 ;; filling example using a 3x4 page matrix:
555 ;; left-top 1 2 3 4 left-bottom 9 10 11 12
557 ;; 9 10 11 12 1 2 3 4
559 ;; right-top 4 3 2 1 right-bottom 12 11 10 9
561 ;; 12 11 10 9 4 3 2 1
563 ;; top-left 1 4 7 10 bottom-left 3 6 9 12
567 ;; top-right 10 7 4 1 bottom-right 12 9 6 3
571 ;; Any other value is treated as left-top.
573 ;; The default value is left-top.
576 ;; Control And 8-bit Characters
577 ;; ----------------------------
579 ;; The variable `ps-print-control-characters' specifies whether you want to see
580 ;; a printable form for control and 8-bit characters, that is, instead of
581 ;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
583 ;; Valid values for `ps-print-control-characters' are:
585 ;; 8-bit This is the value to use when you want an ASCII encoding of
586 ;; any control or non-ASCII character. Control characters are
587 ;; encoded as "^D", and non-ASCII characters have an
590 ;; control-8-bit This is the value to use when you want an ASCII encoding of
591 ;; any control character, whether it is 7 or 8-bit.
592 ;; European 8-bits accented characters are printed according
595 ;; control Only ASCII control characters have an ASCII encoding.
596 ;; European 8-bits accented characters are printed according
599 ;; nil No ASCII encoding. Any character is printed according the
602 ;; Any other value is treated as nil.
604 ;; The default is `control-8-bit'.
606 ;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
609 ;; Printing Multi-byte Buffer
610 ;; --------------------------
612 ;; See ps-mule.el for documentation.
618 ;; The variable `ps-line-number' specifies whether to number each line;
619 ;; non-nil means do so. The default is nil (don't number each line).
621 ;; The variable `ps-line-number-step' specifies the interval that line number is
622 ;; printed. For example, if `ps-line-number-step' is set to 2, the printing
635 ;; integer an integer that specifies the interval that line number is
636 ;; printed. If it's lesser than or equal to zero, it's used the
639 ;; `zebra' specifies that only the line number of the first line in a zebra
640 ;; stripe is to be printed.
642 ;; Any other value is treated as `zebra'.
643 ;; The default value is 1, so each line number is printed.
645 ;; The variable `ps-line-number-start' specifies the starting point in the
646 ;; interval given by `ps-line-number-step'. For example, if
647 ;; `ps-line-number-step' is set to 3 and `ps-line-number-start' is set to 3, the
648 ;; printing will look like:
662 ;; The values for `ps-line-number-start':
664 ;; * If `ps-line-number-step' is an integer, must be between 1 and the value
665 ;; of `ps-line-number-step' inclusive.
667 ;; * If `ps-line-number-step' is set to `zebra', must be between 1 and the
668 ;; value of `ps-zebra-strip-height' inclusive.
670 ;; The default value is 1, so the line number of the first line of each interval
677 ;; Zebra stripes are a kind of background that appear "underneath" the text
678 ;; and can make the text easier to read. They look like this:
680 ;; XXXXXXXXXXXXXXXXXXXXXXXX
681 ;; XXXXXXXXXXXXXXXXXXXXXXXX
682 ;; XXXXXXXXXXXXXXXXXXXXXXXX
686 ;; XXXXXXXXXXXXXXXXXXXXXXXX
687 ;; XXXXXXXXXXXXXXXXXXXXXXXX
688 ;; XXXXXXXXXXXXXXXXXXXXXXXX
690 ;; The blocks of X's represent rectangles filled with a light gray color.
691 ;; Each rectangle extends all the way across the page.
693 ;; The height, in lines, of each rectangle is controlled by
694 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
695 ;; The distance between stripes equals the height of a stripe.
697 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
698 ;; Non-nil means yes, nil means no. The default is nil.
700 ;; The variable `ps-zebra-color' controls the zebra stripes gray scale or RGB
701 ;; color. It should be a float number between 0.0 (black color) and 1.0 (white
702 ;; color), a string which is a color name, or a list of 3 numbers which
703 ;; corresponds to the Red Green Blue color scale.
704 ;; The default is 0.95 (or "gray95", or '(0.95 0.95 0.95)).
706 ;; The variable `ps-zebra-stripe-follow' specifies if zebra stripe should
707 ;; continue on next page or restart on each page. If `ps-zebra-stripe-follow'
708 ;; is nil, zebra stripe is restarted on each page. If `ps-zebra-stripe-follow'
709 ;; is non-nil, zebra stripe continues on next page. Visually, we have:
711 ;; `ps-zebra-stripe-follow' `ps-zebra-stripe-follow'
713 ;; Current Page ------------------------ ------------------------
714 ;; 1 XXXXXXXXXXXXXXXXXXXXX 1 XXXXXXXXXXXXXXXXXXXXX
715 ;; 2 XXXXXXXXXXXXXXXXXXXXX 2 XXXXXXXXXXXXXXXXXXXXX
716 ;; 3 XXXXXXXXXXXXXXXXXXXXX 3 XXXXXXXXXXXXXXXXXXXXX
720 ;; 7 XXXXXXXXXXXXXXXXXXXXX 7 XXXXXXXXXXXXXXXXXXXXX
721 ;; 8 XXXXXXXXXXXXXXXXXXXXX 8 XXXXXXXXXXXXXXXXXXXXX
722 ;; ------------------------ ------------------------
723 ;; Next Page ------------------------ ------------------------
724 ;; 9 XXXXXXXXXXXXXXXXXXXXX 9 XXXXXXXXXXXXXXXXXXXXX
725 ;; 10 XXXXXXXXXXXXXXXXXXXXX 10
726 ;; 11 XXXXXXXXXXXXXXXXXXXXX 11
728 ;; 13 13 XXXXXXXXXXXXXXXXXXXXX
729 ;; 14 14 XXXXXXXXXXXXXXXXXXXXX
730 ;; 15 XXXXXXXXXXXXXXXXXXXXX 15 XXXXXXXXXXXXXXXXXXXXX
731 ;; 16 XXXXXXXXXXXXXXXXXXXXX 16
732 ;; ------------------------ ------------------------
734 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
740 ;; ps-print has the following hook variables:
743 ;; It is evaluated once before any printing process. This is the right
744 ;; place to initialize ps-print global data.
745 ;; For an example, see section Adding a New Font Family.
747 ;; `ps-print-begin-sheet-hook'
748 ;; It is evaluated on each beginning of sheet of paper.
749 ;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
752 ;; `ps-print-begin-page-hook'
753 ;; It is evaluated on each beginning of page, except in the beginning
754 ;; of page that `ps-print-begin-sheet-hook' is evaluated.
756 ;; `ps-print-begin-column-hook'
757 ;; It is evaluated on each beginning of column, except in the beginning
758 ;; of column that `ps-print-begin-page-hook' is evaluated or that
759 ;; `ps-print-begin-sheet-hook' is evaluated.
765 ;; ps-print now knows rather precisely some fonts: the variable
766 ;; `ps-font-info-database' contains information for a list of font families
767 ;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
768 ;; `NewCenturySchlbk'). Each font family contains the font names for standard,
769 ;; bold, italic and bold-italic characters, a reference size (usually 10) and
770 ;; the corresponding line height, width of a space and average character width.
772 ;; The variable `ps-font-family' determines which font family is to be used for
773 ;; ordinary text. If its value does not correspond to a known font family, an
774 ;; error message is printed into the `*Messages*' buffer, which lists the
775 ;; currently available font families.
777 ;; The variable `ps-font-size' determines the size (in points) of the font for
778 ;; ordinary text, when generating PostScript. Its value is a float or a cons of
779 ;; floats which has the following form:
781 ;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
783 ;; Similarly, the variable `ps-header-font-family' determines which font family
784 ;; is to be used for text in the header.
786 ;; The variable `ps-header-font-size' determines the font size, in points, for
787 ;; text in the header (similar to `ps-font-size').
789 ;; The variable `ps-header-title-font-size' determines the font size, in points,
790 ;; for the top line of text in the header (similar to `ps-font-size').
793 ;; Adding a New Font Family
794 ;; ------------------------
796 ;; To use a new font family, you MUST first teach ps-print
797 ;; this font, i.e., add its information to `ps-font-info-database',
798 ;; otherwise ps-print cannot correctly place line and page breaks.
800 ;; For example, assuming `Helvetica' is unknown,
801 ;; you first need to do the following ONLY ONCE:
803 ;; - create a new buffer
804 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
805 ;; - open this file and find the line:
806 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
807 ;; - delete the leading `%' (which is the PostScript comment character)
808 ;; - replace in this line `Courier' by the new font (say `Helvetica')
810 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
811 ;; - send this file to the printer (or to ghostscript).
812 ;; You should read the following on the output page:
814 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
815 ;; and a crude estimate of average character width is 5.09243
817 ;; - Add these values to the `ps-font-info-database':
818 ;; (setq ps-font-info-database
820 ;; '((Helvetica ; the family key
821 ;; (fonts (normal . "Helvetica")
822 ;; (bold . "Helvetica-Bold")
823 ;; (italic . "Helvetica-Oblique")
824 ;; (bold-italic . "Helvetica-BoldOblique"))
826 ;; (line-height . 11.56)
827 ;; (space-width . 2.78)
828 ;; (avg-char-width . 5.09243)))
829 ;; ps-font-info-database))
830 ;; - Now you can use this font family with any size:
831 ;; (setq ps-font-family 'Helvetica)
832 ;; - if you want to use this family in another emacs session, you must
833 ;; put into your `~/.emacs':
834 ;; (require 'ps-print)
835 ;; (setq ps-font-info-database (append ...)))
836 ;; if you don't want to load ps-print, you have to copy the whole value:
837 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
838 ;; or, use `ps-print-hook' (see section Hooks):
839 ;; (add-hook 'ps-print-hook
841 ;; (or (assq 'Helvetica ps-font-info-database)
842 ;; (setq ps-font-info-database (append ...)))))
844 ;; You can create new `mixed' font families like:
846 ;; (fonts (normal . "Courier-Bold")
847 ;; (bold . "Helvetica")
848 ;; (italic . "Zapf-Chancery-MediumItalic")
849 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
850 ;; (w3-table-hack-x-face . "LineDrawNormal"))
852 ;; (line-height . 10.55)
853 ;; (space-width . 6.0)
854 ;; (avg-char-width . 6.0))
856 ;; Now you can use your new font family with any size:
857 ;; (setq ps-font-family 'my-mixed-family)
859 ;; Note that on above example the `w3-table-hack-x-face' entry refers to
860 ;; a face symbol, so when printing this face it'll be used the font
861 ;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
862 ;; use bold and/or italic attribute, the corresponding entry (bold, italic
863 ;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
865 ;; Note also that the font family entry order is irrelevant, so the above
866 ;; example could also be written:
869 ;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
870 ;; (bold . "Helvetica")
871 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
872 ;; (italic . "Zapf-Chancery-MediumItalic")
873 ;; (normal . "Courier-Bold"))
874 ;; (avg-char-width . 6.0)
875 ;; (space-width . 6.0)
876 ;; (line-height . 10.55))
878 ;; Despite the note above, it is recommended that some convention about
879 ;; entry order be used.
881 ;; You can get information on all the fonts resident in YOUR printer
882 ;; by uncommenting the line:
883 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
885 ;; The PostScript file should be sent to YOUR PostScript printer.
886 ;; If you send it to ghostscript or to another PostScript printer,
887 ;; you may get slightly different results.
888 ;; Anyway, as ghostscript fonts are autoload, you won't get
892 ;; How Ps-Print Deals With Faces
893 ;; -----------------------------
895 ;; The ps-print-*-with-faces commands attempt to determine which faces
896 ;; should be printed in bold or italic, but their guesses aren't
897 ;; always right. For example, you might want to map colors into faces
898 ;; so that blue faces print in bold, and red faces in italic.
900 ;; It is possible to force ps-print to consider specific faces bold,
901 ;; italic or underline, no matter what font they are displayed in, by setting
902 ;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
903 ;; These variables contain lists of faces that ps-print should consider bold,
904 ;; italic or underline; to set them, put code like the following into your
907 ;; (setq ps-bold-faces '(my-blue-face))
908 ;; (setq ps-italic-faces '(my-red-face))
909 ;; (setq ps-underlined-faces '(my-green-face))
911 ;; Faces like bold-italic that are both bold and italic should go in
914 ;; ps-print keeps internal lists of which fonts are bold and which are
915 ;; italic; these lists are built the first time you invoke ps-print.
916 ;; For the sake of efficiency, the lists are built only once; the same
917 ;; lists are referred in later invocations of ps-print.
919 ;; Because these lists are built only once, it's possible for them to
920 ;; get out of sync, if a face changes, or if new faces are added. To
921 ;; get the lists back in sync, you can set the variable
922 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
923 ;; next time ps-print is invoked. If you need that the lists always be
924 ;; rebuilt when ps-print is invoked, set the variable
925 ;; `ps-always-build-face-reference' to t.
927 ;; If you need to print without worrying about face background color, set the
928 ;; variable `ps-use-face-background' which specifies if face background should
929 ;; be used. Valid values are:
931 ;; t always use face background color.
932 ;; nil never use face background color.
933 ;; (face...) list of faces whose background color will be used.
935 ;; Any other value will be treated as t.
936 ;; The default value is t.
939 ;; How Ps-Print Deals With Color
940 ;; -----------------------------
942 ;; ps-print detects faces with foreground and background colors
943 ;; defined and embeds color information in the PostScript image.
944 ;; The default foreground and background colors are defined by the
945 ;; variables `ps-default-fg' and `ps-default-bg'.
946 ;; On black-and-white printers, colors are displayed in gray scale.
947 ;; To turn off color output, set `ps-print-color-p' to nil.
950 ;; How Ps-Print Maps Faces
951 ;; -----------------------
953 ;; As ps-print uses PostScript to print buffers, it is possible to have
954 ;; other attributes associated with faces. So the new attributes used
957 ;; strikeout - like underline, but the line is in middle of text.
958 ;; overline - like underline, but the line is over the text.
959 ;; shadow - text will have a shadow.
960 ;; box - text will be surrounded by a box.
961 ;; outline - print characters as hollow outlines.
963 ;; See the documentation for `ps-extend-face'.
965 ;; Let's, for example, remap `font-lock-keyword-face' to another foreground
966 ;; color and bold attribute:
968 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
970 ;; If you want to use a new face, define it first with `defface',
971 ;; and then call `ps-extend-face' to specify how to print it.
974 ;; How Ps-Print Has A Text And/Or Image On Background
975 ;; --------------------------------------------------
977 ;; ps-print can print texts and/or EPS PostScript images on background; it is
978 ;; possible to define the following text attributes: font name, font size,
979 ;; initial position, angle, gray scale and pages to print.
981 ;; It has the following EPS PostScript images attributes: file name containing
982 ;; the image, initial position, X and Y scales, angle and pages to print.
984 ;; See documentation for `ps-print-background-text' and
985 ;; `ps-print-background-image'.
987 ;; For example, if we wish to print text "preliminary" on all pages and text
988 ;; "special" on page 5 and from page 11 to page 17, we could specify:
990 ;; (setq ps-print-background-text
993 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
994 ;; ; (upper left corner)
996 ;; "PrintHeight neg PrintPageWidth atan" ; angle
997 ;; 5 (11 . 17)) ; page list
1000 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
1001 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
1004 ;; (setq ps-print-background-image
1005 ;; '(("~/images/EPS-image1.ps"
1006 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
1007 ;; ("~/images/EPS-image2.ps"
1008 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
1009 ;; ; (upper left corner)
1011 ;; 5 (11 . 17)) ; page list
1014 ;; If it is not possible to read (or does not exist) an image file, that file
1017 ;; The printing order is:
1019 ;; 1. Print background color
1020 ;; 2. Print zebra stripes
1021 ;; 3. Print background texts that it should be on all pages
1022 ;; 4. Print background images that it should be on all pages
1023 ;; 5. Print background texts only for current page (if any)
1024 ;; 6. Print background images only for current page (if any)
1026 ;; 8. Print buffer text (with faces, if specified) and line number
1032 ;; Some tools are provided to help you customize your font setup.
1034 ;; `ps-setup' returns (some part of) the current setup.
1036 ;; To avoid wrapping too many lines, you may want to adjust the
1037 ;; left and right margins and the font size. On UN*X systems, do:
1038 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
1039 ;; to determine the longest lines of your file.
1040 ;; Then, the command `ps-line-lengths' will give you the correspondence
1041 ;; between a line length (number of characters) and the maximum font
1042 ;; size which doesn't wrap such a line with the current ps-print setup.
1044 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
1045 ;; the correspondence between a number of pages and the maximum font
1046 ;; size which allow the number of lines of the current buffer or of
1047 ;; its current region to fit in this number of pages.
1049 ;; NOTE: line folding is not taken into account in this process and could
1050 ;; change the results.
1052 ;; The command `ps-print-customize' activates a customization buffer for
1053 ;; ps-print options.
1056 ;; New since version 1.5
1057 ;; ---------------------
1059 ;; Color output capability.
1060 ;; Automatic detection of font attributes (bold, italic).
1061 ;; Configurable headers with page numbers.
1063 ;; Support for different paper sizes.
1064 ;; Better conformance to PostScript Document Structure Conventions.
1067 ;; New since version 2.8
1068 ;; ---------------------
1070 ;; [vinicius] 20000310 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1072 ;; PostScript error handler.
1073 ;; `ps-user-defined-prologue' and `ps-error-handler-message'.
1075 ;; [vinicius] 991211 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1077 ;; `ps-print-customize'.
1079 ;; [vinicius] 990703 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1081 ;; Better customization.
1082 ;; `ps-banner-page-when-duplexing' and `ps-zebra-color'.
1084 ;; [vinicius] 990513 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1087 ;; Hook: `ps-print-begin-sheet-hook'.
1089 ;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
1091 ;; `ps-print-region-function'
1093 ;; [vinicius] 990301 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1095 ;; PostScript tumble and setpagedevice.
1097 ;; [vinicius] 980922 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1099 ;; PostScript prologue header comment insertion.
1100 ;; Skip invisible text better.
1102 ;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
1104 ;; Multi-byte buffer handling.
1106 ;; [vinicius] 980306 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1108 ;; Skip invisible text.
1110 ;; [vinicius] 971130 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1112 ;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
1113 ;; `ps-print-begin-column-hook'.
1114 ;; Put one header per page over the columns.
1115 ;; Better database font management.
1116 ;; Better control characters handling.
1118 ;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1120 ;; Dynamic evaluation at print time of `ps-lpr-switches'.
1121 ;; Handle control characters.
1123 ;; New face attributes.
1126 ;; Text and/or image on background.
1128 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
1130 ;; Font family and float size for text and header.
1132 ;; Multiple columns.
1133 ;; Tools for page setup.
1136 ;; Known bugs and limitations of ps-print
1137 ;; --------------------------------------
1139 ;; Although color printing will work in XEmacs 19.12, it doesn't work
1140 ;; well; in particular, bold or italic fonts don't print in the right
1141 ;; background color.
1143 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
1145 ;; Automatic font-attribute detection doesn't work well, especially
1146 ;; with hilit19 and older versions of get-create-face. Users having
1147 ;; problems with auto-font detection should use the lists
1148 ;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
1149 ;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
1151 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
1152 ;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
1153 ;; `ps-underlined-faces' instead.
1155 ;; Still too slow; could use some hand-optimization.
1157 ;; Default background color isn't working.
1159 ;; Faces are always treated as opaque.
1161 ;; Epoch and Emacs 19 not supported. At all.
1163 ;; Fixed-pitch fonts work better for line folding, but are not required.
1165 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
1166 ;; of folding lines.
1172 ;; Avoid page break inside a paragraph.
1173 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
1174 ;; Improve the memory management for big files (hard?).
1175 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1176 ;; of folding lines.
1182 ;; Thanks to Paul Furnanz <pfurnanz@synopsys.com> for XEmacs compatibility
1183 ;; suggestion for `ps-postscript-code-directory' variable.
1185 ;; Thanks to David X Callaway <dxc@xprt.net> for helping debugging PostScript
1186 ;; level 1 compatibility.
1188 ;; Thanks to Colin Marquardt <colin.marquardt@usa.alcatel.com> for upside-down,
1189 ;; line number step, line number start and zebra stripe follow suggestions, and
1190 ;; for XEmacs beta-tests.
1192 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for user defined PostScript
1193 ;; prologue code suggestion.
1195 ;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
1197 ;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1200 ;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1203 ;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1204 ;; `ps-print-control-characters' variable documentation.
1206 ;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1207 ;; database font management.
1209 ;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
1210 ;; header per page over the columns and correct line numbers when printing a
1213 ;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1214 ;; print time of `ps-lpr-switches'.
1216 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1217 ;; (his code was severely modified, but the main idea was kept).
1219 ;; Thanks to some suggestions on:
1220 ;; * Face color map: Marco Melgazzi <marco@techie.com>
1221 ;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
1222 ;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
1224 ;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1225 ;; I started from. [vinicius]
1227 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1230 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1231 ;; color and the invisible property.
1233 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1234 ;; the initial port to Emacs 19. His code is no longer part of
1235 ;; ps-print, but his work is still appreciated.
1237 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1238 ;; for adding underline support. Their code also is no longer part of
1239 ;; ps-print, but their efforts are not forgotten.
1241 ;; Thanks also to all of you who mailed code to add features to
1242 ;; ps-print; although I didn't use your code, I still appreciate your
1243 ;; sharing it with me.
1245 ;; Thanks to all who mailed comments, encouragement, and criticism.
1246 ;; Thanks also to all who responded to my survey; I had too many
1247 ;; responses to reply to them all, but I greatly appreciate your
1251 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1255 (unless (featurep 'lisp-float-type
)
1256 (error "`ps-print' requires floating point support"))
1259 ;; For Emacs 20.2 and the earlier version.
1261 (or (fboundp 'set-buffer-multibyte
)
1262 (defun set-buffer-multibyte (arg)
1263 (setq enable-multibyte-characters arg
)))
1265 (or (fboundp 'string-as-unibyte
)
1266 (defun string-as-unibyte (arg) arg
))
1268 (or (fboundp 'string-as-multibyte
)
1269 (defun string-as-multibyte (arg) arg
))
1271 (or (fboundp 'charset-after
)
1272 (defun charset-after (&optional arg
)
1273 (char-charset (char-after arg
))))
1276 (or (fboundp 'line-beginning-position
)
1277 (defun line-beginning-position (&optional n
)
1279 (and n
(/= n
1) (forward-line (1- n
)))
1284 (defconst ps-windows-system
1285 (memq system-type
'(emx win32 w32 mswindows ms-dos windows-nt
)))
1286 (defconst ps-lp-system
1287 (memq system-type
'(usq-unix-v dgux hpux irix
)))
1290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1294 ;;; Interface to the command system
1296 (defgroup postscript nil
1301 (defgroup ps-print nil
1302 "PostScript generator for Emacs 19"
1307 (defgroup ps-print-horizontal nil
1308 "Horizontal page layout"
1313 (defgroup ps-print-vertical nil
1314 "Vertical page layout"
1319 (defgroup ps-print-headers nil
1325 (defgroup ps-print-font nil
1326 "Fonts customization"
1331 (defgroup ps-print-color nil
1332 "Color customization"
1337 (defgroup ps-print-face nil
1338 "Faces customization"
1344 (defgroup ps-print-n-up nil
1345 "N-up customization"
1350 (defgroup ps-print-zebra nil
1351 "Zebra customization"
1356 (defgroup ps-print-background nil
1357 "Background customization"
1362 (defgroup ps-print-printer nil
1363 "Printer customization"
1368 (defgroup ps-print-page nil
1369 "Page customization"
1374 (defgroup ps-print-miscellany nil
1375 "Miscellany customization"
1381 (defcustom ps-error-handler-message
'paper
1382 "*Specify where the error handler message should be sent.
1386 `none' catch the error and *DON'T* send any message.
1388 `paper' catch the error and print on paper the error message.
1390 `system' catch the error and send back the error message to
1391 printing system. This is useful only if printing system
1392 send back an email reporting the error, or if there is
1393 some other alternative way to report back the error from
1396 `paper-and-system' catch the error, print on paper the error message and
1397 send back the error message to printing system.
1399 Any other value is treated as `paper'."
1400 :type
'(choice :menu-tag
"Error Handler Message"
1401 :tag
"Error Handler Message"
1402 (const none
) (const paper
)
1403 (const system
) (const paper-and-system
))
1404 :group
'ps-print-miscellany
)
1406 (defcustom ps-user-defined-prologue nil
1407 "*User defined PostScript prologue code inserted before all prologue code.
1409 `ps-user-defined-prologue' may be a string or a symbol function which returns a
1410 string. Note that this string is inserted after `ps-adobe-tag' and PostScript
1411 prologue comments, and before ps-print PostScript prologue code section. That
1412 is, this string is inserted after error handler initialization and before
1415 It's recommended to initiate and terminate the string with \"\\n\".
1417 It's strongly recommended only insert PostScript code and/or comments specific
1418 for your printing system particularities. For example, some special
1419 initialization that only your printing system needs.
1421 Do not insert code for duplex printing, n-up printing or error handler, ps-print
1422 handles this in a suitable way.
1424 For more information about PostScript, see:
1425 PostScript Language Reference Manual (2nd edition)
1426 Adobe Systems Incorporated"
1427 :type
'(choice :menu-tag
"User Defined Prologue"
1428 :tag
"User Defined Prologue"
1429 (const :tag
"none" nil
) string symbol
)
1430 :group
'ps-print-miscellany
)
1432 (defcustom ps-print-prologue-header nil
1433 "*PostScript prologue header comments besides that ps-print generates.
1435 `ps-print-prologue-header' may be a string or a symbol function which
1436 returns a string. Note that this string is inserted on PostScript prologue
1437 header section which is used to define some document characteristic through
1438 PostScript special comments, like \"%%Requirements: jog\\n\".
1440 ps-print always inserts the %%Requirements: comment, so if you need to insert
1441 more requirements put them first in `ps-print-prologue-header' using the
1442 \"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1443 requirements and set %%LanguageLevel: to 2, do:
1445 (setq ps-print-prologue-header
1446 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1448 The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1450 Do not forget to terminate the string with \"\\n\".
1452 For more information about PostScript document comments, see:
1453 PostScript Language Reference Manual (2nd edition)
1454 Adobe Systems Incorporated
1455 Appendix G: Document Structuring Conventions -- Version 3.0"
1456 :type
'(choice :menu-tag
"Prologue Header"
1457 :tag
"Prologue Header"
1458 (const :tag
"none" nil
) string symbol
)
1459 :group
'ps-print-miscellany
)
1461 (defcustom ps-printer-name
(and (boundp 'printer-name
)
1463 "*The name of a local printer for printing PostScript files.
1465 On Unix-like systems, a string value should be a name understood by
1466 lpr's -P option; a value of nil means use the value of `printer-name'
1467 instead. Any other value will be ignored.
1469 On MS-DOS and MS-Windows systems, a string value is taken as the name of
1470 the printer device or port to which PostScript files are written,
1471 provided `ps-lpr-command' is \"\". By default it is the same as
1472 `printer-name'; typical non-default settings would be \"LPT1\" to
1473 \"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1474 serial printers, or \"//hostname/printer\" for a shared network printer.
1475 You can also set it to a name of a file, in which case the output gets
1476 appended to that file. \(Note that `ps-print' package already has
1477 facilities for printing to a file, so you might as well use them instead
1478 of changing the setting of this variable.\) If you want to silently
1479 discard the printed output, set this to \"NUL\"."
1480 :type
'(choice :menu-tag
"Printer Name"
1482 (const :tag
"Same as printer-name" nil
)
1483 (file :tag
"Print to file")
1484 (string :tag
"Pipe to ps-lpr-command"))
1485 :group
'ps-print-printer
)
1487 (defcustom ps-lpr-command lpr-command
1488 "*Name of program for printing a PostScript file.
1490 On MS-DOS and MS-Windows systems, if the value is an empty string then
1491 Emacs will write directly to the printer port named by `ps-printer-name'.
1492 The programs `print' and `nprint' (the standard print programs on Windows
1493 NT and Novell Netware respectively) are handled specially, using
1494 `ps-printer-name' as the destination for output; any other program is
1495 treated like `lpr' except that an explicit filename is given as the last
1498 :group
'ps-print-printer
)
1500 (defcustom ps-lpr-switches lpr-switches
1501 "*A list of extra switches to pass to `ps-lpr-command'."
1502 :type
'(repeat :tag
"PostScript lpr Switches"
1503 (choice string symbol
(repeat sexp
)))
1504 :group
'ps-print-printer
)
1506 (defcustom ps-print-region-function nil
1507 "*Specify a function to print the region on a PostScript printer.
1508 See definition of `call-process-region' for calling conventions. The fourth and
1509 the sixth arguments are both nil."
1511 :group
'ps-print-printer
)
1513 (defcustom ps-manual-feed nil
1514 "*Non-nil means the printer will manually feed paper.
1516 If it's nil, automatic feeding takes place."
1518 :group
'ps-print-printer
)
1522 ;; All page dimensions are in PostScript points.
1523 ;; 1 inch == 2.54 cm == 72 points
1524 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1526 ;; Letter 8.5 inch x 11.0 inch
1527 ;; Legal 8.5 inch x 14.0 inch
1528 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1530 ;; LetterSmall 7.68 inch x 10.16 inch
1531 ;; Tabloid 11.0 inch x 17.0 inch
1532 ;; Ledger 17.0 inch x 11.0 inch
1533 ;; Statement 5.5 inch x 8.5 inch
1534 ;; Executive 7.5 inch x 10.0 inch
1535 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1536 ;; A4Small 7.47 inch x 10.85 inch
1537 ;; B4 10.125 inch x 14.33 inch
1538 ;; B5 7.16 inch x 10.125 inch
1540 (defcustom ps-page-dimensions-database
1541 (list (list 'a4
(/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1542 (list 'a3
(/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1543 (list 'letter
(* 72 8.5) (* 72 11.0) "Letter")
1544 (list 'legal
(* 72 8.5) (* 72 14.0) "Legal")
1545 (list 'letter-small
(* 72 7.68) (* 72 10.16) "LetterSmall")
1546 (list 'tabloid
(* 72 11.0) (* 72 17.0) "Tabloid")
1547 (list 'ledger
(* 72 17.0) (* 72 11.0) "Ledger")
1548 (list 'statement
(* 72 5.5) (* 72 8.5) "Statement")
1549 (list 'executive
(* 72 7.5) (* 72 10.0) "Executive")
1550 (list 'a4small
(* 72 7.47) (* 72 10.85) "A4Small")
1551 (list 'b4
(* 72 10.125) (* 72 14.33) "B4")
1552 (list 'b5
(* 72 7.16) (* 72 10.125) "B5"))
1553 "*List associating a symbolic paper type to its width, height and doc media.
1554 See `ps-paper-type'."
1555 :type
'(repeat (list :tag
"Paper Type"
1556 (symbol :tag
"Name")
1557 (number :tag
"Width")
1558 (number :tag
"Height")
1559 (string :tag
"Media")))
1560 :group
'ps-print-page
)
1563 (defcustom ps-paper-type
'letter
1564 "*Specify the size of paper to format for.
1565 Should be one of the paper types defined in `ps-page-dimensions-database', for
1566 example `letter', `legal' or `a4'."
1567 :type
'(symbol :validate
(lambda (wid)
1568 (if (assq (widget-value wid
)
1569 ps-page-dimensions-database
)
1571 (widget-put wid
:error
"Unknown paper size")
1573 :group
'ps-print-page
)
1575 (defcustom ps-warn-paper-type t
1576 "*Non-nil means give an error if paper size is not equal to `ps-paper-type'.
1578 It's used when `ps-spool-config' is set to `setpagedevice'."
1580 :group
'ps-print-page
)
1582 (defcustom ps-landscape-mode nil
1583 "*Non-nil means print in landscape mode."
1585 :group
'ps-print-page
)
1587 (defcustom ps-print-upside-down nil
1588 "*Non-nil means print upside-down."
1590 :group
'ps-print-page
)
1592 (defcustom ps-print-control-characters
'control-8-bit
1593 "*Specify the printable form for control and 8-bit characters.
1594 That is, instead of sending, for example, a ^D (\\004) to printer,
1595 it is sent the string \"^D\".
1599 `8-bit' This is the value to use when you want an ASCII encoding of
1600 any control or non-ASCII character. Control characters are
1601 encoded as \"^D\", and non-ASCII characters have an
1604 `control-8-bit' This is the value to use when you want an ASCII encoding of
1605 any control character, whether it is 7 or 8-bit.
1606 European 8-bits accented characters are printed according
1609 `control' Only ASCII control characters have an ASCII encoding.
1610 European 8-bits accented characters are printed according
1613 nil No ASCII encoding. Any character is printed according the
1616 Any other value is treated as nil."
1617 :type
'(choice :menu-tag
"Control Char"
1619 (const 8-bit
) (const control-8-bit
)
1620 (const control
) (const :tag
"nil" nil
))
1621 :group
'ps-print-miscellany
)
1623 (defcustom ps-n-up-printing
1
1624 "*Specify the number of pages per sheet paper."
1626 :tag
"N Up Printing"
1629 (if (and (< 0 (widget-value wid
))
1630 (<= (widget-value wid
) 100))
1634 "Number of pages per sheet paper must be between 1 and 100.")
1636 :group
'ps-print-n-up
)
1638 (defcustom ps-n-up-margin
(/ (* 72 1.0) 2.54) ; 1 cm
1639 "*Specify the margin in points between the sheet border and n-up printing."
1641 :group
'ps-print-n-up
)
1643 (defcustom ps-n-up-border-p t
1644 "*Non-nil means a border is drawn around each page."
1646 :group
'ps-print-n-up
)
1648 (defcustom ps-n-up-filling
'left-top
1649 "*Specify how page matrix is filled on each sheet of paper.
1651 Following are the valid values for `ps-n-up-filling' with a filling example
1652 using a 3x4 page matrix:
1654 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1658 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1662 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1666 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1670 Any other value is treated as `left-top'."
1671 :type
'(choice :menu-tag
"N-Up Filling"
1673 (const left-top
) (const left-bottom
)
1674 (const right-top
) (const right-bottom
)
1675 (const top-left
) (const bottom-left
)
1676 (const top-right
) (const bottom-right
))
1677 :group
'ps-print-n-up
)
1679 (defcustom ps-number-of-columns
(if ps-landscape-mode
2 1)
1680 "*Specify the number of columns"
1682 :group
'ps-print-miscellany
)
1684 (defcustom ps-zebra-stripes nil
1685 "*Non-nil means print zebra stripes.
1686 See also documentation for `ps-zebra-stripe-height' and `ps-zebra-color'."
1688 :group
'ps-print-zebra
)
1690 (defcustom ps-zebra-stripe-height
3
1691 "*Number of zebra stripe lines.
1692 See also documentation for `ps-zebra-stripes' and `ps-zebra-color'."
1694 :group
'ps-print-zebra
)
1696 (defcustom ps-zebra-color
0.95
1697 "*Zebra stripe gray scale or RGB color.
1698 See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
1699 :type
'(choice :menu-tag
"Zebra Gray/Color"
1700 :tag
"Zebra Gray/Color"
1701 (number :tag
"Gray Scale" :value
0.95)
1702 (string :tag
"Color Name" :value
"gray95")
1703 (list :tag
"RGB Color" :value
(0.95
0.95 0.95)
1705 (number :tag
"Green")
1706 (number :tag
"Blue")))
1707 :group
'ps-print-zebra
)
1709 (defcustom ps-zebra-stripe-follow nil
1710 "*Non-nil means zebra stripe continues on next page.
1712 If `ps-zebra-stripe-follow' is nil, zebra stripe is restarted on each page.
1713 If `ps-zebra-stripe-follow' is non-nil, zebra stripe continues on next page.
1717 `ps-zebra-stripe-follow' `ps-zebra-stripe-follow'
1719 Current Page ------------------------ ------------------------
1720 1 XXXXXXXXXXXXXXXXXXXXX 1 XXXXXXXXXXXXXXXXXXXXX
1721 2 XXXXXXXXXXXXXXXXXXXXX 2 XXXXXXXXXXXXXXXXXXXXX
1722 3 XXXXXXXXXXXXXXXXXXXXX 3 XXXXXXXXXXXXXXXXXXXXX
1726 7 XXXXXXXXXXXXXXXXXXXXX 7 XXXXXXXXXXXXXXXXXXXXX
1727 8 XXXXXXXXXXXXXXXXXXXXX 8 XXXXXXXXXXXXXXXXXXXXX
1728 ------------------------ ------------------------
1729 Next Page ------------------------ ------------------------
1730 9 XXXXXXXXXXXXXXXXXXXXX 9 XXXXXXXXXXXXXXXXXXXXX
1731 10 XXXXXXXXXXXXXXXXXXXXX 10
1732 11 XXXXXXXXXXXXXXXXXXXXX 11
1734 13 13 XXXXXXXXXXXXXXXXXXXXX
1735 14 14 XXXXXXXXXXXXXXXXXXXXX
1736 15 XXXXXXXXXXXXXXXXXXXXX 15 XXXXXXXXXXXXXXXXXXXXX
1737 16 XXXXXXXXXXXXXXXXXXXXX 16
1738 ------------------------ ------------------------"
1740 :group
'ps-print-zebra
)
1742 (defcustom ps-line-number nil
1743 "*Non-nil means print line number."
1745 :group
'ps-print-miscellany
)
1747 (defcustom ps-line-number-step
1
1748 "*Specify the interval that line number is printed.
1750 For example, `ps-line-number-step' is set to 2, the printing will look like:
1762 integer an integer that specifies the interval that line number is
1763 printed. If it's lesser than or equal to zero, it's used the
1766 `zebra' specifies that only the line number of the first line in a zebra
1767 stripe is to be printed.
1769 Any other value is treated as `zebra'."
1770 :type
'(choice :menu-tag
"Line Number Step"
1771 :tag
"Line Number Step"
1772 (integer :tag
"Step Interval")
1773 (const :tag
"Synchronize Zebra" zebra
))
1774 :group
'ps-print-miscellany
)
1776 (defcustom ps-line-number-start
1
1777 "*Specify the starting point in the interval given by `ps-line-number-step'.
1779 For example, if `ps-line-number-step' is set to 3 and `ps-line-number-start' is set to 3, the
1780 printing will look like:
1794 The values for `ps-line-number-start':
1796 * If `ps-line-number-step' is an integer, must be between 1 and the value
1797 of `ps-line-number-step' inclusive.
1799 * If `ps-line-number-step' is set to `zebra', must be between 1 and the
1800 value of `ps-zebra-strip-height' inclusive. Use this combination if you
1801 wish that line number be relative to zebra stripes."
1802 :type
'(integer :tag
"Start Step Interval")
1803 :group
'ps-print-miscellany
)
1805 (defcustom ps-print-background-image nil
1806 "*EPS image list to be printed on background.
1810 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1812 FILENAME is a file name which contains an EPS image or some PostScript
1813 programming like EPS.
1814 FILENAME is ignored, if it doesn't exist or is read protected.
1816 X and Y are relative positions on paper to put the image.
1817 If X and Y are nil, the image is centralized on paper.
1819 XSCALE and YSCALE are scale factor to be applied to image before printing.
1820 If XSCALE and YSCALE are nil, the original size is used.
1822 ROTATION is the image rotation angle; if nil, the default is 0.
1824 PAGES designates the page to print background image.
1825 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1827 If PAGES is nil, print background image on all pages.
1829 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1830 an integer number or a string. If it is a string, the string should contain
1831 PostScript programming that returns a float or integer value.
1833 For example, if you wish to print an EPS image on all pages do:
1835 '((\"~/images/EPS-image.ps\"))"
1838 (file :tag
"EPS File")
1839 (choice :tag
"X" (const :tag
"default" nil
) number string
)
1840 (choice :tag
"Y" (const :tag
"default" nil
) number string
)
1841 (choice :tag
"X Scale" (const :tag
"default" nil
) number string
)
1842 (choice :tag
"Y Scale" (const :tag
"default" nil
) number string
)
1843 (choice :tag
"Rotation" (const :tag
"default" nil
) number string
)
1844 (repeat :tag
"Pages" :inline t
1845 (radio (integer :tag
"Page")
1847 (integer :tag
"From")
1848 (integer :tag
"To"))))))
1849 :group
'ps-print-background
)
1851 (defcustom ps-print-background-text nil
1852 "*Text list to be printed on background.
1856 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1858 STRING is the text to be printed on background.
1860 X and Y are positions on paper to put the text.
1861 If X and Y are nil, the text is positioned at lower left corner.
1863 FONT is a font name to be used on printing the text.
1864 If nil, \"Times-Roman\" is used.
1866 FONTSIZE is font size to be used, if nil, 200 is used.
1868 GRAY is the text gray factor (should be very light like 0.8).
1869 If nil, the default is 0.85.
1871 ROTATION is the text rotation angle; if nil, the angle is given by
1872 the diagonal from lower left corner to upper right corner.
1874 PAGES designates the page to print background text.
1875 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1877 If PAGES is nil, print background text on all pages.
1879 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1880 an integer number or a string. If it is a string, the string should contain
1881 PostScript programming that returns a float or integer value.
1883 For example, if you wish to print text \"Preliminary\" on all pages do:
1885 '((\"Preliminary\"))"
1888 (string :tag
"Text")
1889 (choice :tag
"X" (const :tag
"default" nil
) number string
)
1890 (choice :tag
"Y" (const :tag
"default" nil
) number string
)
1891 (choice :tag
"Font" (const :tag
"default" nil
) string
)
1892 (choice :tag
"Fontsize" (const :tag
"default" nil
) number string
)
1893 (choice :tag
"Gray" (const :tag
"default" nil
) number string
)
1894 (choice :tag
"Rotation" (const :tag
"default" nil
) number string
)
1895 (repeat :tag
"Pages" :inline t
1896 (radio (integer :tag
"Page")
1898 (integer :tag
"From")
1899 (integer :tag
"To"))))))
1900 :group
'ps-print-background
)
1902 ;;; Horizontal layout
1904 ;; ------------------------------------------
1906 ;; | lm | text | ic | text | ic | text | rm |
1908 ;; ------------------------------------------
1910 (defcustom ps-left-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1911 "*Left margin in points (1/72 inch)."
1913 :group
'ps-print-horizontal
)
1915 (defcustom ps-right-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1916 "*Right margin in points (1/72 inch)."
1918 :group
'ps-print-horizontal
)
1920 (defcustom ps-inter-column
(/ (* 72 2.0) 2.54) ; 2 cm
1921 "*Horizontal space between columns in points (1/72 inch)."
1923 :group
'ps-print-horizontal
)
1939 (defcustom ps-bottom-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1940 "*Bottom margin in points (1/72 inch)."
1942 :group
'ps-print-vertical
)
1944 (defcustom ps-top-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1945 "*Top margin in points (1/72 inch)."
1947 :group
'ps-print-vertical
)
1949 (defcustom ps-header-offset
(/ (* 72 1.0) 2.54) ; 1.0 cm
1950 "*Vertical space in points (1/72 inch) between the main text and the header."
1952 :group
'ps-print-vertical
)
1954 (defcustom ps-header-line-pad
0.15
1955 "*Portion of a header title line height to insert between the header frame
1956 and the text it contains, both in the vertical and horizontal directions."
1958 :group
'ps-print-vertical
)
1962 (defcustom ps-print-header t
1963 "*Non-nil means print a header at the top of each page.
1964 By default, the header displays the buffer name, page number, and, if
1965 the buffer is visiting a file, the file's directory. Headers are
1966 customizable by changing variables `ps-left-header' and
1969 :group
'ps-print-headers
)
1971 (defcustom ps-print-only-one-header nil
1972 "*Non-nil means print only one header at the top of each page.
1973 This is useful when printing more than one column, so it is possible
1974 to have only one header over all columns or one header per column.
1975 See also `ps-print-header'."
1977 :group
'ps-print-headers
)
1979 (defcustom ps-print-header-frame t
1980 "*Non-nil means draw a gaudy frame around the header."
1982 :group
'ps-print-headers
)
1984 (defcustom ps-header-lines
2
1985 "*Number of lines to display in page header, when generating PostScript."
1987 :group
'ps-print-headers
)
1989 (defcustom ps-switch-header
'duplex
1990 "*Specify if headers are switched or not.
1994 nil Never switch headers.
1996 t Always switch headers.
1998 duplex Switch headers only when duplexing is on, that is, when
1999 `ps-spool-duplex' is non-nil.
2001 Any other value is treated as t."
2002 :type
'(choice :menu-tag
"Switch Header"
2003 :tag
"Switch Header"
2004 (const :tag
"Never Switch" nil
)
2005 (const :tag
"Always Switch" t
)
2006 (const :tag
"Switch When Duplexing" duplex
))
2007 :group
'ps-print-headers
)
2009 (defcustom ps-show-n-of-n t
2010 "*Non-nil means show page numbers as N/M, meaning page N of M.
2011 NOTE: page numbers are displayed as part of headers,
2012 see variable `ps-print-header'."
2014 :group
'ps-print-headers
)
2016 (defcustom ps-spool-config
2017 (if ps-windows-system
2020 "*Specify who is responsable for setting duplex and page size switches.
2024 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
2025 Don't forget to set `ps-lpr-switches' to select duplex
2026 printing for your printer.
2028 `setpagedevice' duplex and page size are configured by ps-print using the
2029 setpagedevice PostScript operator.
2031 nil duplex and page size are configured by ps-print *not* using
2032 the setpagedevice PostScript operator.
2034 Any other value is treated as nil.
2036 WARNING: The setpagedevice PostScript operator affects ghostview utility when
2037 viewing file generated using landscape. Also on some printers,
2038 setpagedevice affects zebra stripes; on other printers, setpagedevice
2039 affects the left margin.
2040 Besides all that, if your printer does not have the paper size
2041 specified by setpagedevice, your printing will be aborted.
2042 So, if you need to use setpagedevice, set `ps-spool-config' to
2043 `setpagedevice', generate a test file and send it to your printer; if
2044 the printed file isn't ok, set `ps-spool-config' to nil."
2045 :type
'(choice :menu-tag
"Spool Config"
2047 (const lpr-switches
) (const setpagedevice
)
2048 (const :tag
"nil" nil
))
2049 :group
'ps-print-headers
)
2051 (defcustom ps-spool-duplex nil
; Not many people have duplex printers,
2052 ; so default to nil.
2053 "*Non-nil generates PostScript for a two-sided printer.
2054 For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
2055 blank pages as needed between print jobs so that the next buffer printed will
2056 start on the right page. Also, if headers are turned on, the headers will be
2057 reversed on duplex printers so that the page numbers fall to the left on
2058 even-numbered pages.
2060 See also `ps-spool-tumble'."
2062 :group
'ps-print-headers
)
2064 (defcustom ps-spool-tumble nil
2065 "*Specify how the page images on opposite sides of a sheet are oriented.
2066 If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
2067 right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
2070 It has effect only when `ps-spool-duplex' is non-nil."
2072 :group
'ps-print-headers
)
2076 (defcustom ps-font-info-database
2077 '((Courier ; the family key
2078 (fonts (normal .
"Courier")
2079 (bold .
"Courier-Bold")
2080 (italic .
"Courier-Oblique")
2081 (bold-italic .
"Courier-BoldOblique"))
2083 (line-height .
10.55)
2085 (avg-char-width .
6.0))
2086 (Helvetica ; the family key
2087 (fonts (normal .
"Helvetica")
2088 (bold .
"Helvetica-Bold")
2089 (italic .
"Helvetica-Oblique")
2090 (bold-italic .
"Helvetica-BoldOblique"))
2092 (line-height .
11.56)
2093 (space-width .
2.78)
2094 (avg-char-width .
5.09243))
2096 (fonts (normal .
"Times-Roman")
2097 (bold .
"Times-Bold")
2098 (italic .
"Times-Italic")
2099 (bold-italic .
"Times-BoldItalic"))
2101 (line-height .
11.0)
2103 (avg-char-width .
4.71432))
2105 (fonts (normal .
"Palatino-Roman")
2106 (bold .
"Palatino-Bold")
2107 (italic .
"Palatino-Italic")
2108 (bold-italic .
"Palatino-BoldItalic"))
2110 (line-height .
12.1)
2112 (avg-char-width .
5.08676))
2114 (fonts (normal .
"Helvetica-Narrow")
2115 (bold .
"Helvetica-Narrow-Bold")
2116 (italic .
"Helvetica-Narrow-Oblique")
2117 (bold-italic .
"Helvetica-Narrow-BoldOblique"))
2119 (line-height .
11.56)
2120 (space-width .
2.2796)
2121 (avg-char-width .
4.17579))
2123 (fonts (normal .
"NewCenturySchlbk-Roman")
2124 (bold .
"NewCenturySchlbk-Bold")
2125 (italic .
"NewCenturySchlbk-Italic")
2126 (bold-italic .
"NewCenturySchlbk-BoldItalic"))
2128 (line-height .
12.15)
2129 (space-width .
2.78)
2130 (avg-char-width .
5.31162))
2131 ;; got no bold for the next ones
2133 (fonts (normal .
"AvantGarde-Book")
2134 (italic .
"AvantGarde-BookOblique"))
2136 (line-height .
11.77)
2137 (space-width .
2.77)
2138 (avg-char-width .
5.45189))
2140 (fonts (normal .
"AvantGarde-Demi")
2141 (italic .
"AvantGarde-DemiOblique"))
2143 (line-height .
12.72)
2145 (avg-char-width .
5.51351))
2147 (fonts (normal .
"Bookman-Demi")
2148 (italic .
"Bookman-DemiItalic"))
2150 (line-height .
11.77)
2152 (avg-char-width .
6.05946))
2154 (fonts (normal .
"Bookman-Light")
2155 (italic .
"Bookman-LightItalic"))
2157 (line-height .
11.79)
2159 (avg-char-width .
5.67027))
2160 ;; got no bold and no italic for the next ones
2162 (fonts (normal .
"Symbol"))
2164 (line-height .
13.03)
2166 (avg-char-width .
3.24324))
2168 (fonts (normal .
"Zapf-Dingbats"))
2170 (line-height .
9.63)
2171 (space-width .
2.78)
2172 (avg-char-width .
2.78))
2173 (Zapf-Chancery-MediumItalic
2174 (fonts (normal .
"Zapf-Chancery-MediumItalic"))
2176 (line-height .
11.45)
2178 (avg-char-width .
4.10811))
2180 "*Font info database: font family (the key), name, bold, italic, bold-italic,
2181 reference size, line height, space width, average character width.
2182 To get the info for another specific font (say Helvetica), do the following:
2183 - create a new buffer
2184 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
2185 - open this file and delete the leading `%' (which is the PostScript
2186 comment character) from the line
2187 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
2189 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
2190 - add the values to `ps-font-info-database'.
2191 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
2192 :type
'(repeat (list :tag
"Font Definition"
2193 (symbol :tag
"Font Family")
2195 (const :format
"" fonts
)
2196 (repeat :tag
"Faces"
2197 (cons (choice (const normal
)
2201 (symbol :tag
"Face"))
2202 (string :tag
"Font Name"))))
2204 (const :format
"" size
)
2205 (number :tag
"Reference Size"))
2207 (const :format
"" line-height
)
2208 (number :tag
"Line Height"))
2210 (const :format
"" space-width
)
2211 (number :tag
"Space Width"))
2213 (const :format
"" avg-char-width
)
2214 (number :tag
"Average Character Width"))))
2215 :group
'ps-print-font
)
2217 (defcustom ps-font-family
'Courier
2218 "*Font family name for ordinary text, when generating PostScript."
2220 :group
'ps-print-font
)
2222 (defcustom ps-font-size
'(7 .
8.5)
2223 "*Font size, in points, for ordinary text, when generating PostScript."
2224 :type
'(choice (number :tag
"Text Size")
2225 (cons :tag
"Landscape/Portrait"
2226 (number :tag
"Landscape Text Size")
2227 (number :tag
"Portrait Text Size")))
2228 :group
'ps-print-font
)
2230 (defcustom ps-header-font-family
'Helvetica
2231 "*Font family name for text in the header, when generating PostScript."
2233 :group
'ps-print-font
)
2235 (defcustom ps-header-font-size
'(10 .
12)
2236 "*Font size, in points, for text in the header, when generating PostScript."
2237 :type
'(choice (number :tag
"Header Size")
2238 (cons :tag
"Landscape/Portrait"
2239 (number :tag
"Landscape Header Size")
2240 (number :tag
"Portrait Header Size")))
2241 :group
'ps-print-font
)
2243 (defcustom ps-header-title-font-size
'(12 .
14)
2244 "*Font size, in points, for the top line of text in header, in PostScript."
2245 :type
'(choice (number :tag
"Header Title Size")
2246 (cons :tag
"Landscape/Portrait"
2247 (number :tag
"Landscape Header Title Size")
2248 (number :tag
"Portrait Header Title Size")))
2249 :group
'ps-print-font
)
2253 ;; Printing color requires x-color-values.
2254 (defcustom ps-print-color-p
(or (fboundp 'x-color-values
) ; Emacs
2255 (fboundp 'color-instance-rgb-components
))
2257 "*Non-nil means print the buffer's text in color."
2259 :group
'ps-print-color
)
2261 (defcustom ps-default-fg
'(0.0
0.0 0.0)
2262 "*RGB values of the default foreground color. Defaults to black."
2263 :type
'(choice :menu-tag
"Default Foreground Gray/Color"
2264 :tag
"Default Foreground Gray/Color"
2265 (number :tag
"Gray Scale" :value
0.0)
2266 (string :tag
"Color Name" :value
"black")
2267 (list :tag
"RGB Color" :value
(0.0
0.0 0.0)
2269 (number :tag
"Green")
2270 (number :tag
"Blue")))
2271 :group
'ps-print-color
)
2273 (defcustom ps-default-bg
'(1.0
1.0 1.0)
2274 "*RGB values of the default background color. Defaults to white."
2275 :type
'(choice :menu-tag
"Default Background Gray/Color"
2276 :tag
"Default Background Gray/Color"
2277 (number :tag
"Gray Scale" :value
1.0)
2278 (string :tag
"Color Name" :value
"white")
2279 (list :tag
"RGB Color" :value
(1.0
1.0 1.0)
2281 (number :tag
"Green")
2282 (number :tag
"Blue")))
2283 :group
'ps-print-color
)
2285 (defcustom ps-auto-font-detect t
2286 "*Non-nil means automatically detect bold/italic face attributes.
2287 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
2288 and `ps-underlined-faces'."
2290 :group
'ps-print-font
)
2292 (defcustom ps-bold-faces
2293 (unless ps-print-color-p
2294 '(font-lock-function-name-face
2295 font-lock-builtin-face
2296 font-lock-variable-name-face
2297 font-lock-keyword-face
2298 font-lock-warning-face
))
2299 "*A list of the \(non-bold\) faces that should be printed in bold font.
2300 This applies to generating PostScript."
2301 :type
'(repeat face
)
2302 :group
'ps-print-face
)
2304 (defcustom ps-italic-faces
2305 (unless ps-print-color-p
2306 '(font-lock-variable-name-face
2308 font-lock-string-face
2309 font-lock-comment-face
2310 font-lock-warning-face
))
2311 "*A list of the \(non-italic\) faces that should be printed in italic font.
2312 This applies to generating PostScript."
2313 :type
'(repeat face
)
2314 :group
'ps-print-face
)
2316 (defcustom ps-underlined-faces
2317 (unless ps-print-color-p
2318 '(font-lock-function-name-face
2319 font-lock-constant-face
2320 font-lock-warning-face
))
2321 "*A list of the \(non-underlined\) faces that should be printed underlined.
2322 This applies to generating PostScript."
2323 :type
'(repeat face
)
2324 :group
'ps-print-face
)
2326 (defcustom ps-use-face-background nil
2327 "*Specify if face background should be used.
2331 t always use face background color.
2332 nil never use face background color.
2333 (face...) list of faces whose background color will be used.
2335 Any other value will be treated as t."
2336 :type
'(choice :menu-tag
"Use Face Background"
2337 :tag
"Use Face Background"
2338 (const :tag
"Always Use Face Background" t
)
2339 (const :tag
"Never Use Face Background" nil
)
2340 (repeat :menu-tag
"Face Background List"
2341 :tag
"Face Background List"
2343 :group
'ps-print-face
)
2345 (defcustom ps-left-header
2346 (list 'ps-get-buffer-name
'ps-header-dirpart
)
2347 "*The items to display (each on a line) on the left part of the page header.
2348 This applies to generating PostScript.
2350 The value should be a list of strings and symbols, each representing an
2351 entry in the PostScript array HeaderLinesLeft.
2353 Strings are inserted unchanged into the array; those representing
2354 PostScript string literals should be delimited with PostScript string
2355 delimiters '(' and ')'.
2357 For symbols with bound functions, the function is called and should
2358 return a string to be inserted into the array. For symbols with bound
2359 values, the value should be a string to be inserted into the array.
2360 In either case, function or variable, the string value has PostScript
2361 string delimiters added to it."
2362 :type
'(repeat (choice string symbol
))
2363 :group
'ps-print-headers
)
2365 (defcustom ps-right-header
2366 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy
'time-stamp-hh
:mm
:ss
)
2367 "*The items to display (each on a line) on the right part of the page header.
2368 This applies to generating PostScript.
2370 See the variable `ps-left-header' for a description of the format of
2372 :type
'(repeat (choice string symbol
))
2373 :group
'ps-print-headers
)
2375 (defcustom ps-razzle-dazzle t
2376 "*Non-nil means report progress while formatting buffer."
2378 :group
'ps-print-miscellany
)
2380 (defcustom ps-adobe-tag
"%!PS-Adobe-3.0\n"
2381 "*Contains the header line identifying the output as PostScript.
2382 By default, `ps-adobe-tag' contains the standard identifier. Some
2383 printers require slightly different versions of this line."
2385 :group
'ps-print-miscellany
)
2387 (defcustom ps-build-face-reference t
2388 "*Non-nil means build the reference face lists.
2390 ps-print sets this value to nil after it builds its internal reference
2391 lists of bold and italic faces. By settings its value back to t, you
2392 can force ps-print to rebuild the lists the next time you invoke one
2393 of the ...-with-faces commands.
2395 You should set this value back to t after you change the attributes of
2396 any face, or create new faces. Most users shouldn't have to worry
2397 about its setting, though."
2399 :group
'ps-print-face
)
2401 (defcustom ps-always-build-face-reference nil
2402 "*Non-nil means always rebuild the reference face lists.
2404 If this variable is non-nil, ps-print will rebuild its internal
2405 reference lists of bold and italic faces *every* time one of the
2406 ...-with-faces commands is called. Most users shouldn't need to set this
2409 :group
'ps-print-face
)
2411 (defcustom ps-banner-page-when-duplexing nil
2412 "*Non-nil means the very first page is skipped.
2413 It's like the very first character of buffer (or region) is ^L (\\014)."
2415 :group
'ps-print-headers
)
2417 (defcustom ps-postscript-code-directory
2418 (or (and (fboundp 'locate-data-directory
) ; xemacs
2419 (locate-data-directory "ps-print"))
2420 data-directory
) ; emacs
2421 "*Directory where it's located the PostScript prologue file used by ps-print.
2422 By default, this directory is the same as in the variable `data-directory'."
2424 :group
'ps-print-miscellany
)
2427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2432 (defun ps-print-customize ()
2433 "Customization of ps-print group."
2435 (customize-group 'ps-print
))
2438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2443 (defun ps-print-buffer (&optional filename
)
2444 "Generate and print a PostScript image of the buffer.
2446 Interactively, when you use a prefix argument (C-u), the command
2447 prompts the user for a file name, and saves the PostScript image
2448 in that file instead of sending it to the printer.
2450 Noninteractively, the argument FILENAME is treated as follows: if it
2451 is nil, send the image to the printer. If FILENAME is a string, save
2452 the PostScript image in a file with that name."
2453 (interactive (list (ps-print-preprint current-prefix-arg
)))
2454 (ps-print-without-faces (point-min) (point-max) filename
))
2458 (defun ps-print-buffer-with-faces (&optional filename
)
2459 "Generate and print a PostScript image of the buffer.
2460 Like `ps-print-buffer', but includes font, color, and underline
2461 information in the generated image. This command works only if you
2462 are using a window system, so it has a way to determine color values."
2463 (interactive (list (ps-print-preprint current-prefix-arg
)))
2464 (ps-print-with-faces (point-min) (point-max) filename
))
2468 (defun ps-print-region (from to
&optional filename
)
2469 "Generate and print a PostScript image of the region.
2470 Like `ps-print-buffer', but prints just the current region."
2471 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2472 (ps-print-without-faces from to filename t
))
2476 (defun ps-print-region-with-faces (from to
&optional filename
)
2477 "Generate and print a PostScript image of the region.
2478 Like `ps-print-region', but includes font, color, and underline
2479 information in the generated image. This command works only if you
2480 are using a window system, so it has a way to determine color values."
2481 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2482 (ps-print-with-faces from to filename t
))
2486 (defun ps-spool-buffer ()
2487 "Generate and spool a PostScript image of the buffer.
2488 Like `ps-print-buffer' except that the PostScript image is saved in a
2489 local buffer to be sent to the printer later.
2491 Use the command `ps-despool' to send the spooled images to the printer."
2493 (ps-spool-without-faces (point-min) (point-max)))
2497 (defun ps-spool-buffer-with-faces ()
2498 "Generate and spool a PostScript image of the buffer.
2499 Like `ps-spool-buffer', but includes font, color, and underline
2500 information in the generated image. This command works only if you
2501 are using a window system, so it has a way to determine color values.
2503 Use the command `ps-despool' to send the spooled images to the printer."
2505 (ps-spool-with-faces (point-min) (point-max)))
2509 (defun ps-spool-region (from to
)
2510 "Generate a PostScript image of the region and spool locally.
2511 Like `ps-spool-buffer', but spools just the current region.
2513 Use the command `ps-despool' to send the spooled images to the printer."
2515 (ps-spool-without-faces from to t
))
2519 (defun ps-spool-region-with-faces (from to
)
2520 "Generate a PostScript image of the region and spool locally.
2521 Like `ps-spool-region', but includes font, color, and underline
2522 information in the generated image. This command works only if you
2523 are using a window system, so it has a way to determine color values.
2525 Use the command `ps-despool' to send the spooled images to the printer."
2527 (ps-spool-with-faces from to t
))
2530 (defun ps-despool (&optional filename
)
2531 "Send the spooled PostScript to the printer.
2533 Interactively, when you use a prefix argument (C-u), the command
2534 prompts the user for a file name, and saves the spooled PostScript
2535 image in that file instead of sending it to the printer.
2537 Noninteractively, the argument FILENAME is treated as follows: if it
2538 is nil, send the image to the printer. If FILENAME is a string, save
2539 the PostScript image in a file with that name."
2540 (interactive (list (ps-print-preprint current-prefix-arg
)))
2541 (ps-do-despool filename
))
2544 (defun ps-line-lengths ()
2545 "Display the correspondence between a line length and a font size,
2546 using the current ps-print setup.
2547 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2549 (ps-line-lengths-internal))
2552 (defun ps-nb-pages-buffer (nb-lines)
2553 "Display number of pages to print this buffer, for various font heights.
2554 The table depends on the current ps-print setup."
2555 (interactive (list (count-lines (point-min) (point-max))))
2556 (ps-nb-pages nb-lines
))
2559 (defun ps-nb-pages-region (nb-lines)
2560 "Display number of pages to print the region, for various font heights.
2561 The table depends on the current ps-print setup."
2562 (interactive (list (count-lines (mark) (point))))
2563 (ps-nb-pages nb-lines
))
2567 "Return the current PostScript-generation setup."
2570 ;;; ps-print version %s
2571 \(setq ps-print-color-p %s
2575 ps-print-region-function %s
2579 ps-warn-paper-type %s
2580 ps-landscape-mode %s
2581 ps-print-upside-down %s
2582 ps-number-of-columns %s
2585 ps-zebra-stripe-height %s
2586 ps-zebra-stripe-follow %S
2589 ps-line-number-step %s
2590 ps-line-number-start %S
2595 ps-use-face-background %s
2597 ps-print-control-characters %s
2599 ps-print-background-image %s
2601 ps-print-background-text %s
2603 ps-error-handler-message %s
2604 ps-user-defined-prologue %s
2605 ps-print-prologue-header %s
2613 ps-header-line-pad %s
2615 ps-print-only-one-header %s
2616 ps-print-header-frame %s
2623 ps-banner-page-when-duplexing %s
2630 ps-multibyte-buffer %s
2633 ps-header-font-family %s
2634 ps-header-font-size %s
2635 ps-header-title-font-size %s)
2640 (ps-print-quote ps-lpr-switches
)
2642 (ps-print-quote ps-print-region-function
)
2644 (ps-print-quote ps-paper-type
)
2647 ps-print-upside-down
2648 ps-number-of-columns
2650 ps-zebra-stripe-height
2651 ps-zebra-stripe-follow
2652 (ps-print-quote ps-zebra-color
)
2654 (ps-print-quote ps-line-number-step
)
2655 ps-line-number-start
2656 (ps-print-quote ps-default-fg
)
2657 (ps-print-quote ps-default-bg
)
2658 (ps-print-quote ps-use-face-background
)
2659 (ps-print-quote ps-print-control-characters
)
2660 (ps-print-quote ps-print-background-image
)
2661 (ps-print-quote ps-print-background-text
)
2662 (ps-print-quote ps-error-handler-message
)
2663 (ps-print-quote ps-user-defined-prologue
)
2664 (ps-print-quote ps-print-prologue-header
)
2673 ps-print-only-one-header
2674 ps-print-header-frame
2675 (ps-print-quote ps-switch-header
)
2678 (ps-print-quote ps-spool-config
)
2681 ps-banner-page-when-duplexing
2685 (ps-print-quote ps-n-up-filling
)
2686 (ps-print-quote ps-multibyte-buffer
) ; see `ps-mule.el'
2687 (ps-print-quote ps-font-family
)
2688 (ps-print-quote ps-font-size
)
2689 (ps-print-quote ps-header-font-family
)
2690 (ps-print-quote ps-header-font-size
)
2691 (ps-print-quote ps-header-title-font-size
)))
2694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2695 ;; Utility functions and variables:
2698 (defun ps-print-quote (sym)
2701 ((or (symbolp sym
) (listp sym
))
2708 (defvar ps-print-emacs-type
2709 (cond ((string-match "XEmacs" emacs-version
) 'xemacs
)
2710 ((string-match "Lucid" emacs-version
) 'lucid
)
2711 ((string-match "Epoch" emacs-version
) 'epoch
)
2714 (if (or (eq ps-print-emacs-type
'lucid
)
2715 (eq ps-print-emacs-type
'xemacs
))
2716 (if (< emacs-minor-version
12)
2717 (setq ps-print-color-p nil
))
2718 (require 'faces
)) ; face-font, face-underline-p,
2721 ;; Return t if the device (which can be changed during an emacs session)
2722 ;; can handle colors.
2723 ;; This is function is not yet implemented for GNU emacs.
2724 (cond ((and (eq ps-print-emacs-type
'xemacs
)
2725 (>= emacs-minor-version
12)) ; xemacs
2726 (defun ps-color-device ()
2727 (eq (device-class) 'color
))
2731 (defun ps-color-device ()
2736 (require 'time-stamp
)
2739 (defun ps-prologue-file (filenumber)
2741 (let* ((filename (format "%sps-prin%d.ps"
2742 ps-postscript-code-directory filenumber
))
2744 (or (find-file-noselect filename
'no-warn
'rawfile
)
2745 (error "ps-print PostScript prologue `%s' file was not found."
2750 (kill-buffer buffer
)))))
2753 (defvar ps-mark-code-directory nil
)
2755 (defvar ps-print-prologue-0
""
2756 "ps-print PostScript error handler.")
2758 (defvar ps-print-prologue-1
""
2759 "ps-print PostScript prologue begin.")
2761 (defvar ps-print-prologue-2
""
2762 "ps-print PostScript prologue end.")
2764 (defvar ps-print-duplex-feature
""
2765 "ps-print PostScript duplex feature.")
2767 ;; Start Editing Here:
2769 (defvar ps-source-buffer nil
)
2770 (defvar ps-spool-buffer-name
"*PostScript*")
2771 (defvar ps-spool-buffer nil
)
2773 (defvar ps-output-head nil
)
2774 (defvar ps-output-tail nil
)
2776 (defvar ps-page-postscript
0)
2777 (defvar ps-page-order
0)
2778 (defvar ps-page-count
0)
2779 (defvar ps-showline-count
1)
2781 (defvar ps-control-or-escape-regexp nil
)
2782 (defvar ps-n-up-on nil
)
2784 (defvar ps-background-pages nil
)
2785 (defvar ps-background-all-pages nil
)
2786 (defvar ps-background-text-count
0)
2787 (defvar ps-background-image-count
0)
2789 (defvar ps-current-font
0)
2790 (defvar ps-default-foreground nil
)
2791 (defvar ps-default-color nil
)
2792 (defvar ps-current-color nil
)
2793 (defvar ps-current-bg nil
)
2795 (defvar ps-razchunk
0)
2797 (defvar ps-color-p nil
)
2798 (defvar ps-color-format
2799 (if (eq ps-print-emacs-type
'emacs
)
2801 ;; Emacs understands the %f format; we'll use it to limit color RGB
2802 ;; values to three decimals to cut down some on the size of the
2803 ;; PostScript output.
2806 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2809 ;; These values determine how much print-height to deduct when headers
2810 ;; are turned on. This is a pretty clumsy way of handling it, but
2811 ;; it'll do for now.
2813 (defvar ps-header-pad
0
2814 "Vertical and horizontal space between the header frame and the text.
2815 This is in units of points (1/72 inch).")
2817 ;; Define accessors to the dimensions list.
2819 (defmacro ps-page-dimensions-get-width
(dims) `(nth 0 ,dims
))
2820 (defmacro ps-page-dimensions-get-height
(dims) `(nth 1 ,dims
))
2821 (defmacro ps-page-dimensions-get-media
(dims) `(nth 2 ,dims
))
2823 (defvar ps-landscape-page-height nil
)
2825 (defvar ps-print-width nil
)
2826 (defvar ps-print-height nil
)
2828 (defvar ps-height-remaining nil
)
2829 (defvar ps-width-remaining nil
)
2831 (defvar ps-print-color-scale nil
)
2833 (defvar ps-font-size-internal nil
)
2834 (defvar ps-header-font-size-internal nil
)
2835 (defvar ps-header-title-font-size-internal nil
)
2838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2839 ;; Internal Variables
2842 (defvar ps-print-face-extension-alist nil
2843 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2844 An element of this list has the following form:
2846 (FACE . [BITS FG BG])
2848 FACE is a symbol denoting a face name
2849 BITS is a bit vector, where each bit correspond
2850 to a feature (bold, underline, etc)
2851 (see documentation for `ps-print-face-map-alist')
2852 FG foreground color (string or nil)
2853 BG background color (string or nil)
2855 Don't change this list directly; instead,
2856 use `ps-extend-face' and `ps-extend-face-list'.
2857 See documentation for `ps-extend-face' for valid extension symbol.")
2860 (defvar ps-print-face-alist nil
2861 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2863 An element of this list has the same form as an element of
2864 `ps-print-face-extension-alist'.
2866 Don't change this list directly; this list is used by `ps-face-attributes',
2867 `ps-map-face' and `ps-build-reference-face-lists'.")
2870 (defconst ps-print-face-map-alist
2879 "Alist of all features and the corresponding bit mask.
2880 Each symbol correspond to one bit in a bit vector.")
2883 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2888 (defun ps-extend-face-list (face-extension-list &optional merge-p
)
2889 "Extend face in `ps-print-face-extension-alist'.
2891 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2892 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2894 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2896 See `ps-extend-face' for documentation."
2897 (while face-extension-list
2898 (ps-extend-face (car face-extension-list
) merge-p
)
2899 (setq face-extension-list
(cdr face-extension-list
))))
2903 (defun ps-extend-face (face-extension &optional merge-p
)
2904 "Extend face in `ps-print-face-extension-alist'.
2906 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2907 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2909 The elements of FACE-EXTENSION list have the form:
2911 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2913 FACE-NAME is a face name symbol.
2915 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2916 foreground and background colors respectively.
2918 EXTENSION is one of the following symbols:
2919 bold - use bold font.
2920 italic - use italic font.
2921 underline - put a line under text.
2922 strikeout - like underline, but the line is in middle of text.
2923 overline - like underline, but the line is over the text.
2924 shadow - text will have a shadow.
2925 box - text will be surrounded by a box.
2926 outline - print characters as hollow outlines.
2928 If EXTENSION is any other symbol, it is ignored."
2929 (let* ((face-name (nth 0 face-extension
))
2930 (foreground (nth 1 face-extension
))
2931 (background (nth 2 face-extension
))
2932 (ps-face (cdr (assq face-name ps-print-face-extension-alist
)))
2933 (face-vector (or ps-face
(vector 0 nil nil
)))
2934 (face-bit (ps-extension-bit face-extension
)))
2936 (aset face-vector
0 (if merge-p
2937 (logior (aref face-vector
0) face-bit
)
2939 (and foreground
(stringp foreground
) (aset face-vector
1 foreground
))
2940 (and background
(stringp background
) (aset face-vector
2 background
))
2941 ;; if face does not exist, insert it
2943 (setq ps-print-face-extension-alist
2944 (cons (cons face-name face-vector
)
2945 ps-print-face-extension-alist
)))))
2948 (defun ps-extension-bit (face-extension)
2950 ;; map valid symbol extension to bit vector
2951 (setq face-extension
(cdr (cdr face-extension
)))
2952 (while (setq face-extension
(cdr face-extension
))
2953 (setq face-bit
(logior face-bit
2954 (or (cdr (assq (car face-extension
)
2955 ps-print-face-map-alist
))
2960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2961 ;; Adapted from font-lock: (obsolete stuff)
2962 ;; Originally face attributes were specified via `font-lock-face-attributes'.
2963 ;; Users then changed the default face attributes by setting that variable.
2964 ;; However, we try and be back-compatible and respect its value if set except
2965 ;; for faces where M-x customize has been used to save changes for the face.
2968 (defun ps-font-lock-face-attributes ()
2969 (and (boundp 'font-lock-mode
) (symbol-value 'font-lock-mode
)
2970 (boundp 'font-lock-face-attributes
)
2971 (let ((face-attributes font-lock-face-attributes
))
2972 (while face-attributes
2973 (let* ((face-attribute
2974 (car (prog1 face-attributes
2975 (setq face-attributes
(cdr face-attributes
)))))
2976 (face (car face-attribute
)))
2977 ;; Rustle up a `defface' SPEC from a
2978 ;; `font-lock-face-attributes' entry.
2979 (unless (get face
'saved-face
)
2980 (let ((foreground (nth 1 face-attribute
))
2981 (background (nth 2 face-attribute
))
2982 (bold-p (nth 3 face-attribute
))
2983 (italic-p (nth 4 face-attribute
))
2984 (underline-p (nth 5 face-attribute
))
2987 (setq face-spec
(cons ':foreground
2988 (cons foreground face-spec
))))
2990 (setq face-spec
(cons ':background
2991 (cons background face-spec
))))
2993 (setq face-spec
(append '(:bold t
) face-spec
)))
2995 (setq face-spec
(append '(:italic t
) face-spec
)))
2997 (setq face-spec
(append '(:underline t
) face-spec
)))
2998 (custom-declare-face face
(list (list t face-spec
)) nil
)
3002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3003 ;; Internal functions and variables
3006 (make-local-hook 'ps-print-hook
)
3007 (make-local-hook 'ps-print-begin-sheet-hook
)
3008 (make-local-hook 'ps-print-begin-page-hook
)
3009 (make-local-hook 'ps-print-begin-column-hook
)
3012 (defun ps-print-without-faces (from to
&optional filename region-p
)
3013 (ps-spool-without-faces from to region-p
)
3014 (ps-do-despool filename
))
3017 (defun ps-spool-without-faces (from to
&optional region-p
)
3018 (run-hooks 'ps-print-hook
)
3019 (ps-printing-region region-p from
)
3020 (ps-generate (current-buffer) from to
'ps-generate-postscript
))
3023 (defun ps-print-with-faces (from to
&optional filename region-p
)
3024 (ps-spool-with-faces from to region-p
)
3025 (ps-do-despool filename
))
3028 (defun ps-spool-with-faces (from to
&optional region-p
)
3029 (run-hooks 'ps-print-hook
)
3030 (ps-printing-region region-p from
)
3031 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
))
3034 (defun ps-count-lines (from to
)
3035 (+ (count-lines from to
)
3038 (if (= (current-column) 0) 1 0))))
3041 (defvar ps-printing-region nil
3042 "Variable used to indicate if the region that ps-print is printing.
3043 It is a cons, the car of which is the line number where the region begins, and
3044 its cdr is the total number of lines in the buffer. Formatting functions can
3045 use this information to print the original line number (and not the number of
3046 lines printed), and to indicate in the header that the printout is of a partial
3050 (defvar ps-printing-region-p nil
3051 "Non-nil means ps-print is printing a region.")
3054 (defun ps-printing-region (region-p from
)
3055 (setq ps-printing-region-p region-p
3058 (ps-count-lines (point-min) from
)
3060 (ps-count-lines (point-min) (point-max)))))
3063 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3064 ;; Internal functions
3067 (defsubst ps-font-alist
(font-sym)
3068 (get font-sym
'fonts
))
3070 (defun ps-font (font-sym font-type
)
3071 "Font family name for text of `font-type', when generating PostScript."
3072 (let* ((font-list (ps-font-alist font-sym
))
3073 (normal-font (cdr (assq 'normal font-list
))))
3074 (while (and font-list
(not (eq font-type
(car (car font-list
)))))
3075 (setq font-list
(cdr font-list
)))
3076 (or (cdr (car font-list
)) normal-font
)))
3078 (defun ps-fonts (font-sym)
3079 (mapcar 'cdr
(ps-font-alist font-sym
)))
3081 (defun ps-font-number (font-sym font-type
)
3082 (or (ps-alist-position font-type
(ps-font-alist font-sym
))
3085 (defsubst ps-line-height
(font-sym)
3086 "The height of a line, for generating PostScript.
3087 This is the value that ps-print uses to determine the height,
3088 y-dimension, of the lines of text it has printed, and thus affects the
3089 point at which page-breaks are placed.
3090 The line-height is *not* the same as the point size of the font."
3091 (get font-sym
'line-height
))
3093 (defsubst ps-title-line-height
(font-sym)
3094 "The height of a `title' line, for generating PostScript.
3095 This is the value that ps-print uses to determine the height,
3096 y-dimension, of the lines of text it has printed, and thus affects the
3097 point at which page-breaks are placed.
3098 The title-line-height is *not* the same as the point size of the font."
3099 (get font-sym
'title-line-height
))
3101 (defsubst ps-space-width
(font-sym)
3102 "The width of a space character, for generating PostScript.
3103 This value is used in expanding tab characters."
3104 (get font-sym
'space-width
))
3106 (defsubst ps-avg-char-width
(font-sym)
3107 "The average width, in points, of a character, for generating PostScript.
3108 This is the value that ps-print uses to determine the length,
3109 x-dimension, of the text it has printed, and thus affects the point at
3110 which long lines wrap around."
3111 (get font-sym
'avg-char-width
))
3113 (defun ps-line-lengths-internal ()
3114 "Display the correspondence between a line length and a font size,
3115 using the current ps-print setup.
3116 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
3117 (let ((buf (get-buffer-create "*Line-lengths*"))
3118 (ifs ps-font-size-internal
) ; initial font size
3119 (icw (ps-avg-char-width 'ps-font-for-text
)) ; initial character width
3120 (print-width (progn (ps-get-page-dimensions)
3122 (ps-setup (ps-setup)) ; setup for the current buffer
3123 (fs-min 5) ; minimum font size
3124 cw-min
; minimum character width
3125 nb-cpl-max
; maximum nb of characters per line
3126 (fs-max 14) ; maximum font size
3127 cw-max
; maximum character width
3128 nb-cpl-min
; minimum nb of characters per line
3129 fs
; current font size
3130 cw
; current character width
3131 nb-cpl
; current nb of characters per line
3133 (setq cw-min
(/ (* icw fs-min
) ifs
)
3134 nb-cpl-max
(floor (/ print-width cw-min
))
3135 cw-max
(/ (* icw fs-max
) ifs
)
3136 nb-cpl-min
(floor (/ print-width cw-max
))
3139 (goto-char (point-max))
3140 (or (bolp) (insert "\n"))
3142 "nb char per line / font size\n")
3143 (while (<= nb-cpl nb-cpl-max
)
3144 (setq cw
(/ print-width
(float nb-cpl
))
3145 fs
(/ (* ifs cw
) icw
))
3146 (insert (format "%3s %s\n" nb-cpl fs
))
3147 (setq nb-cpl
(1+ nb-cpl
)))
3149 (display-buffer buf
'not-this-window
)))
3151 (defun ps-nb-pages (nb-lines)
3152 "Display correspondence between font size and the number of pages.
3153 The correspondence is based on having NB-LINES lines of text,
3154 and on the current ps-print setup."
3155 (let ((buf (get-buffer-create "*Nb-Pages*"))
3156 (ifs ps-font-size-internal
) ; initial font size
3157 (ilh (ps-line-height 'ps-font-for-text
)) ; initial line height
3158 (page-height (progn (ps-get-page-dimensions)
3160 (ps-setup (ps-setup)) ; setup for the current buffer
3161 (fs-min 4) ; minimum font size
3162 lh-min
; minimum line height
3163 nb-lpp-max
; maximum nb of lines per page
3164 nb-page-min
; minimum nb of pages
3165 (fs-max 14) ; maximum font size
3166 lh-max
; maximum line height
3167 nb-lpp-min
; minimum nb of lines per page
3168 nb-page-max
; maximum nb of pages
3169 fs
; current font size
3170 lh
; current line height
3171 nb-lpp
; current nb of lines per page
3172 nb-page
; current nb of pages
3174 (setq lh-min
(/ (* ilh fs-min
) ifs
)
3175 nb-lpp-max
(floor (/ page-height lh-min
))
3176 nb-page-min
(ceiling (/ (float nb-lines
) nb-lpp-max
))
3177 lh-max
(/ (* ilh fs-max
) ifs
)
3178 nb-lpp-min
(floor (/ page-height lh-max
))
3179 nb-page-max
(ceiling (/ (float nb-lines
) nb-lpp-min
))
3180 nb-page nb-page-min
)
3182 (goto-char (point-max))
3183 (or (bolp) (insert "\n"))
3185 (format "%d lines\n" nb-lines
)
3186 "nb page / font size\n")
3187 (while (<= nb-page nb-page-max
)
3188 (setq nb-lpp
(ceiling (/ nb-lines
(float nb-page
)))
3189 lh
(/ page-height nb-lpp
)
3190 fs
(/ (* ifs lh
) ilh
))
3191 (insert (format "%s %s\n" nb-page fs
))
3192 (setq nb-page
(1+ nb-page
)))
3194 (display-buffer buf
'not-this-window
)))
3196 ;; macros used in `ps-select-font'
3197 (defmacro ps-lookup
(key) `(cdr (assq ,key font-entry
)))
3198 (defmacro ps-size-scale
(key) `(/ (* (ps-lookup ,key
) font-size
) size
))
3200 (defun ps-select-font (font-family sym font-size title-font-size
)
3201 (let ((font-entry (cdr (assq font-family ps-font-info-database
))))
3203 (error "Don't have data to scale font %s. Known fonts families are %s"
3205 (mapcar 'car ps-font-info-database
)))
3206 (let ((size (ps-lookup 'size
)))
3207 (put sym
'fonts
(ps-lookup 'fonts
))
3208 (put sym
'space-width
(ps-size-scale 'space-width
))
3209 (put sym
'avg-char-width
(ps-size-scale 'avg-char-width
))
3210 (put sym
'line-height
(ps-size-scale 'line-height
))
3211 (put sym
'title-line-height
3212 (/ (* (ps-lookup 'line-height
) title-font-size
) size
)))))
3214 (defun ps-get-page-dimensions ()
3215 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
3216 page-width page-height
)
3218 ((null page-dimensions
)
3219 (error "`ps-paper-type' must be one of:\n%s"
3220 (mapcar 'car ps-page-dimensions-database
)))
3221 ((< ps-number-of-columns
1)
3222 (error "The number of columns %d should be positive"
3223 ps-number-of-columns
)))
3225 (ps-select-font ps-font-family
'ps-font-for-text
3226 ps-font-size-internal ps-font-size-internal
)
3227 (ps-select-font ps-header-font-family
'ps-font-for-header
3228 ps-header-font-size-internal
3229 ps-header-title-font-size-internal
)
3231 (setq page-width
(ps-page-dimensions-get-width page-dimensions
)
3232 page-height
(ps-page-dimensions-get-height page-dimensions
))
3235 (if ps-landscape-mode
3236 ;; exchange width and height
3237 (setq page-width
(prog1 page-height
(setq page-height page-width
))))
3239 ;; It is used to get the lower right corner (only in landscape mode)
3240 (setq ps-landscape-page-height page-height
)
3242 ;; | lm | text | ic | text | ic | text | rm |
3243 ;; page-width == lm + n * pw + (n - 1) * ic + rm
3244 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
3245 (setq ps-print-width
(/ (- page-width
3246 ps-left-margin ps-right-margin
3247 (* (1- ps-number-of-columns
) ps-inter-column
))
3248 ps-number-of-columns
))
3249 (if (<= ps-print-width
0)
3250 (error "Bad horizontal layout:
3252 ps-left-margin == %s
3253 ps-right-margin == %s
3254 ps-inter-column == %s
3255 ps-number-of-columns == %s
3256 | lm | text | ic | text | ic | text | rm |
3257 page-width == lm + n * print-width + (n - 1) * ic + rm
3258 => print-width == %d !"
3263 ps-number-of-columns
3266 (setq ps-print-height
3267 (- page-height ps-bottom-margin ps-top-margin
))
3268 (if (<= ps-print-height
0)
3269 (error "Bad vertical layout:
3271 ps-bottom-margin == %s
3272 page-height == bm + print-height + tm
3273 => print-height == %d !"
3277 ;; If headers are turned on, deduct the height of the header from
3278 ;; the print height.
3280 (setq ps-header-pad
(* ps-header-line-pad
3281 (ps-title-line-height 'ps-font-for-header
))
3282 ps-print-height
(- ps-print-height
3285 (ps-title-line-height 'ps-font-for-header
)
3286 (* (ps-line-height 'ps-font-for-header
)
3287 (1- ps-header-lines
))
3289 (if (<= ps-print-height
0)
3290 (error "Bad vertical layout:
3292 ps-bottom-margin == %s
3293 ps-header-offset == %s
3296 page-height == bm + print-height + tm - ho - hh
3297 => print-height == %d !"
3303 (ps-title-line-height 'ps-font-for-header
)
3304 (* (ps-line-height 'ps-font-for-header
)
3305 (1- ps-header-lines
))
3309 (defun ps-print-preprint (prefix-arg)
3311 (or (numberp prefix-arg
)
3313 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
3316 (prompt (format "Save PostScript to file: (default %s) " name
))
3317 (res (read-file-name prompt default-directory name nil
)))
3318 (while (cond ((not (file-writable-p res
))
3320 (setq prompt
"is unwritable"))
3321 ((file-exists-p res
)
3322 (setq prompt
"exists")
3323 (not (y-or-n-p (format "File `%s' exists; overwrite? "
3326 (setq res
(read-file-name
3327 (format "File %s; save PostScript to file: " prompt
)
3328 (file-name-directory res
) nil nil
3329 (file-name-nondirectory res
))))
3330 (if (file-directory-p res
)
3331 (expand-file-name name
(file-name-as-directory res
))
3334 ;; The following functions implement a simple list-buffering scheme so
3335 ;; that ps-print doesn't have to repeatedly switch between buffers
3336 ;; while spooling. The functions `ps-output' and `ps-output-string' build
3337 ;; up the lists; the function `ps-flush-output' takes the lists and
3338 ;; insert its contents into the spool buffer (*PostScript*).
3340 (defvar ps-string-escape-codes
3341 (let ((table (make-vector 256 nil
))
3343 ;; control characters
3344 (while (<= char ?
\037)
3345 (aset table char
(format "\\%03o" char
))
3346 (setq char
(1+ char
)))
3347 ;; printable characters
3348 (while (< char ?
\177)
3349 (aset table char
(format "%c" char
))
3350 (setq char
(1+ char
)))
3351 ;; DEL and 8-bit characters
3352 (while (<= char ?
\377)
3353 (aset table char
(format "\\%o" char
))
3354 (setq char
(1+ char
)))
3355 ;; Override ASCII formatting characters with named escape code:
3356 (aset table ?
\n "\\n") ; [NL] linefeed
3357 (aset table ?
\r "\\r") ; [CR] carriage return
3358 (aset table ?
\t "\\t") ; [HT] horizontal tab
3359 (aset table ?
\b "\\b") ; [BS] backspace
3360 (aset table ?
\f "\\f") ; [NP] form feed
3361 ;; Escape PostScript escape and string delimiter characters:
3362 (aset table ?
\\ "\\\\")
3363 (aset table ?\
( "\\(")
3364 (aset table ?\
) "\\)")
3366 "Vector used to map characters to PostScript string escape codes.")
3368 (defun ps-output-string-prim (string)
3369 (insert "(") ;insert start-string delimiter
3370 (save-excursion ;insert string
3371 (insert (string-as-unibyte string
)))
3372 ;; Find and quote special characters as necessary for PS
3373 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
3374 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
3375 (let ((special (following-char)))
3377 (insert (aref ps-string-escape-codes special
))))
3378 (goto-char (point-max))
3379 (insert ")")) ;insert end-string delimiter
3381 (defun ps-init-output-queue ()
3382 (setq ps-output-head
'("")
3383 ps-output-tail ps-output-head
))
3385 (defun ps-output (&rest args
)
3386 (setcdr ps-output-tail args
)
3387 (while (cdr ps-output-tail
)
3388 (setq ps-output-tail
(cdr ps-output-tail
))))
3390 (defun ps-output-string (string)
3391 (ps-output t string
))
3393 (defun ps-output-list (the-list)
3394 (mapcar 'ps-output the-list
))
3396 ;; Output strings in the list ARGS in the PostScript prologue part.
3397 (defun ps-output-prologue (args)
3398 (ps-output 'prologue
(if (stringp args
) (list args
) args
)))
3400 (defun ps-flush-output ()
3402 (set-buffer ps-spool-buffer
)
3403 (goto-char (point-max))
3404 (while ps-output-head
3405 (let ((it (car ps-output-head
)))
3408 (setq ps-output-head
(cdr ps-output-head
))
3409 (ps-output-string-prim (car ps-output-head
)))
3411 (setq ps-output-head
(cdr ps-output-head
))
3413 (search-backward "\nBeginDoc")
3415 (apply 'insert
(car ps-output-head
))))
3418 (setq ps-output-head
(cdr ps-output-head
))))
3419 (ps-init-output-queue))
3421 (defun ps-insert-file (fname)
3424 (set-buffer ps-spool-buffer
)
3425 (goto-char (point-max))
3426 (insert-file fname
)))
3428 ;; These functions insert the arrays that define the contents of the
3431 (defun ps-generate-header-line (fonttag &optional content
)
3432 (ps-output " [ " fonttag
" ")
3434 ;; Literal strings should be output as is -- the string must
3435 ;; contain its own PS string delimiters, '(' and ')', if necessary.
3437 (ps-output content
))
3439 ;; Functions are called -- they should return strings; they will be
3440 ;; inserted as strings and the PS string delimiters added.
3441 ((and (symbolp content
) (fboundp content
))
3442 (ps-output-string (funcall content
)))
3444 ;; Variables will have their contents inserted. They should
3445 ;; contain strings, and will be inserted as strings.
3446 ((and (symbolp content
) (boundp content
))
3447 (ps-output-string (symbol-value content
)))
3449 ;; Anything else will get turned into an empty string.
3451 (ps-output-string "")))
3454 (defun ps-generate-header (name contents
)
3455 (ps-output "/" name
" [\n")
3456 (if (> ps-header-lines
0)
3458 (ps-generate-header-line "/h0" (car contents
))
3459 (while (and (< count ps-header-lines
)
3460 (setq contents
(cdr contents
)))
3461 (ps-generate-header-line "/h1" (car contents
))
3462 (setq count
(1+ count
)))
3463 (ps-output "] def\n"))))
3466 (defun ps-output-boolean (name bool
)
3467 (ps-output (format "/%s %s def\n" name
(if bool
"true" "false"))))
3470 (defun ps-background-pages (page-list func
)
3474 (let ((start (if (consp pages
) (car pages
) pages
))
3475 (end (if (consp pages
) (cdr pages
) pages
)))
3476 (and (integerp start
) (integerp end
) (<= start end
)
3477 (add-to-list 'ps-background-pages
(vector start end func
)))))
3479 (setq ps-background-all-pages
(cons func ps-background-all-pages
))))
3482 (defconst ps-boundingbox-re
3484 \\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3487 (defun ps-get-boundingbox ()
3489 (set-buffer ps-spool-buffer
)
3491 (if (re-search-forward ps-boundingbox-re nil t
)
3492 (vector (string-to-number ; lower x
3493 (buffer-substring (match-beginning 1) (match-end 1)))
3494 (string-to-number ; lower y
3495 (buffer-substring (match-beginning 2) (match-end 2)))
3496 (string-to-number ; upper x
3497 (buffer-substring (match-beginning 3) (match-end 3)))
3498 (string-to-number ; upper y
3499 (buffer-substring (match-beginning 4) (match-end 4))))
3500 (vector 0 0 0 0)))))
3503 ;; Emacs understands the %f format; we'll use it to limit color RGB values
3504 ;; to three decimals to cut down some on the size of the PostScript output.
3505 ;; Lucid emacsen will have to make do with %s (princ) for floats.
3507 (defvar ps-float-format
(if (eq ps-print-emacs-type
'emacs
)
3509 "%s ")) ; Lucid emacsen
3512 (defun ps-float-format (value &optional default
)
3513 (let ((literal (or value default
)))
3515 (format (if (numberp literal
)
3522 (defun ps-background-text ()
3525 (setq ps-background-text-count
(1+ ps-background-text-count
))
3526 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count
))
3527 (ps-output-string (nth 0 text
)) ; text
3530 (ps-float-format (nth 4 text
) 200.0) ; font size
3531 (format "/%s " (or (nth 3 text
) "Times-Roman")) ; font name
3532 (ps-float-format (nth 6 text
)
3533 "PrintHeight PrintPageWidth atan") ; rotation
3534 (ps-float-format (nth 5 text
) 0.85) ; gray
3535 (ps-float-format (nth 1 text
) "0") ; x position
3536 (ps-float-format (nth 2 text
) "0") ; y position
3537 "\nShowBackText} def\n")
3538 (ps-background-pages (nthcdr 7 text
) ; page list
3539 (format "ShowBackText-%d\n"
3540 ps-background-text-count
)))
3541 ps-print-background-text
))
3544 (defun ps-background-image ()
3547 (let ((image-file (expand-file-name (nth 0 image
))))
3548 (when (file-readable-p image-file
)
3549 (setq ps-background-image-count
(1+ ps-background-image-count
))
3551 (format "/ShowBackImage-%d {\n--back-- "
3552 ps-background-image-count
)
3553 (ps-float-format (nth 5 image
) 0.0) ; rotation
3554 (ps-float-format (nth 3 image
) 1.0) ; x scale
3555 (ps-float-format (nth 4 image
) 1.0) ; y scale
3556 (ps-float-format (nth 1 image
) ; x position
3557 "PrintPageWidth 2 div")
3558 (ps-float-format (nth 2 image
) ; y position
3559 "PrintHeight 2 div BottomMargin add")
3560 "\nBeginBackImage\n")
3561 (ps-insert-file image-file
)
3562 ;; coordinate adjustment to centralize image
3563 ;; around x and y position
3564 (let ((box (ps-get-boundingbox)))
3566 (set-buffer ps-spool-buffer
)
3568 (if (re-search-backward "^--back--" nil t
)
3572 (- (+ (/ (- (aref box
2) (aref box
0)) 2.0)
3575 (- (+ (/ (- (aref box
3) (aref box
1)) 2.0)
3578 (ps-output "\nEndBackImage} def\n")
3579 (ps-background-pages (nthcdr 6 image
) ; page list
3580 (format "ShowBackImage-%d\n"
3581 ps-background-image-count
)))))
3582 ps-print-background-image
))
3585 (defun ps-background (page-number)
3586 (let (has-local-background)
3587 (mapcar #'(lambda (range)
3588 (and (<= (aref range
0) page-number
)
3589 (<= page-number
(aref range
1))
3590 (if has-local-background
3591 (ps-output (aref range
2))
3592 (setq has-local-background t
)
3593 (ps-output "/printLocalBackground {\n"
3595 ps-background-pages
)
3596 (and has-local-background
(ps-output "} def\n"))))
3599 ;; Return a list of the distinct elements of LIST.
3600 ;; Elements are compared with `equal'.
3601 (defun ps-remove-duplicates (list)
3602 (let (new (tail list
))
3604 (or (member (car tail
) new
)
3605 (setq new
(cons (car tail
) new
)))
3606 (setq tail
(cdr tail
)))
3610 ;; Find the first occurrence of ITEM in LIST.
3611 ;; Return the index of the matching item, or nil if not found.
3612 ;; Elements are compared with `eq'.
3613 (defun ps-alist-position (item list
)
3614 (let ((tail list
) (index 0) found
)
3616 (if (setq found
(eq (car (car tail
)) item
))
3618 (setq index
(1+ index
)
3623 (defconst ps-n-up-database
3674 (2 t
1 2 0) ; adjusted by PostScript code
3717 (2 t
1 2 0) ; adjusted by PostScript code
3762 ;; Ledger paper size is a special case, it is the only paper size where the
3763 ;; normal size is landscaped, that is, the height is smaller than width.
3764 ;; So, we use the special value `pag' in the `landscape' field.
3813 (2 t
1 2 0) ; adjusted by PostScript code
3909 "Alist which is the page matrix database used for N-up printing.
3911 Each element has the following form:
3914 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
3918 PAGE is the page size used (see `ps-paper-type').
3919 MAX is the maximum elements of this page matrix.
3920 LANDSCAPE specifies if page matrix is landscaped, has the following valid
3922 nil the sheet is in portrait mode.
3923 t the sheet is in landscape mode.
3924 pag the sheet is in portrait mode and page is in landscape mode.
3925 LINES is the number of lines of page matrix.
3926 COLUMNS is the number of columns of page matrix.
3927 COL-MISSING is the number of columns missing to fill the sheet.")
3930 (defmacro ps-n-up-landscape
(mat) `(nth 1 ,mat
))
3931 (defmacro ps-n-up-lines
(mat) `(nth 2 ,mat
))
3932 (defmacro ps-n-up-columns
(mat) `(nth 3 ,mat
))
3933 (defmacro ps-n-up-missing
(mat) `(nth 4 ,mat
))
3936 (defun ps-n-up-printing ()
3937 ;; force `ps-n-up-printing' be in range 1 to 100.
3938 (setq ps-n-up-printing
(max (min ps-n-up-printing
100) 1))
3939 ;; find suitable page matrix for a given `ps-paper-type'.
3940 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database
))))
3942 (while (> ps-n-up-printing
(caar the-list
))
3943 (setq the-list
(cdr the-list
))))
3947 (defconst ps-n-up-filling-database
3949 "PageWidth" ; N-Up-XColumn
3951 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3952 "LandscapePageHeight neg" ; N-Up-YLine
3953 "N-Up-Lines" ; N-Up-Repeat
3954 "N-Up-Columns" ; N-Up-End
3958 "PageWidth" ; N-Up-XColumn
3960 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3961 "LandscapePageHeight" ; N-Up-YLine
3962 "N-Up-Lines" ; N-Up-Repeat
3963 "N-Up-Columns" ; N-Up-End
3965 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3967 "PageWidth neg" ; N-Up-XColumn
3969 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3970 "LandscapePageHeight neg" ; N-Up-YLine
3971 "N-Up-Lines" ; N-Up-Repeat
3972 "N-Up-Columns" ; N-Up-End
3973 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3976 "PageWidth neg" ; N-Up-XColumn
3978 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3979 "LandscapePageHeight" ; N-Up-YLine
3980 "N-Up-Lines" ; N-Up-Repeat
3981 "N-Up-Columns" ; N-Up-End
3982 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3983 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3986 "LandscapePageHeight neg" ; N-Up-YColumn
3987 "PageWidth" ; N-Up-XLine
3988 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3989 "N-Up-Columns" ; N-Up-Repeat
3990 "N-Up-Lines" ; N-Up-End
3995 "LandscapePageHeight" ; N-Up-YColumn
3996 "PageWidth" ; N-Up-XLine
3997 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3998 "N-Up-Columns" ; N-Up-Repeat
3999 "N-Up-Lines" ; N-Up-End
4001 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
4004 "LandscapePageHeight neg" ; N-Up-YColumn
4005 "PageWidth neg" ; N-Up-XLine
4006 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
4007 "N-Up-Columns" ; N-Up-Repeat
4008 "N-Up-Lines" ; N-Up-End
4009 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
4013 "LandscapePageHeight" ; N-Up-YColumn
4014 "PageWidth neg" ; N-Up-XLine
4015 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
4016 "N-Up-Columns" ; N-Up-Repeat
4017 "N-Up-Lines" ; N-Up-End
4018 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
4019 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
4020 "Alist for n-up printing initializations.
4022 Each element has the following form:
4024 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
4027 KIND is a valid value of `ps-n-up-filling'.
4028 XCOL YCOL are the relative position for the next column.
4029 XLIN YLIN are the relative position for the beginning of next line.
4030 REPEAT is the number of repetions for external loop.
4031 END is the number of repetions for internal loop and also the number of pages in
4033 XSTART YSTART are the relative position for the first page in a sheet.")
4036 (defun ps-n-up-filling ()
4037 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database
)
4038 (assq 'left-top ps-n-up-filling-database
))))
4041 (defmacro ps-n-up-xcolumn
(init) `(nth 0 ,init
))
4042 (defmacro ps-n-up-ycolumn
(init) `(nth 1 ,init
))
4043 (defmacro ps-n-up-xline
(init) `(nth 2 ,init
))
4044 (defmacro ps-n-up-yline
(init) `(nth 3 ,init
))
4045 (defmacro ps-n-up-repeat
(init) `(nth 4 ,init
))
4046 (defmacro ps-n-up-end
(init) `(nth 5 ,init
))
4047 (defmacro ps-n-up-xstart
(init) `(nth 6 ,init
))
4048 (defmacro ps-n-up-ystart
(init) `(nth 7 ,init
))
4051 (defconst ps-error-handler-alist
4055 (paper-and-system .
3))
4056 "Alist for error handler message")
4059 (defun ps-begin-file ()
4060 (ps-get-page-dimensions)
4061 (setq ps-page-postscript
0
4063 ps-background-text-count
0
4064 ps-background-image-count
0
4065 ps-background-pages nil
4066 ps-background-all-pages nil
)
4068 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
4069 (tumble (if ps-landscape-mode
(not ps-spool-tumble
) ps-spool-tumble
))
4070 (n-up (ps-n-up-printing))
4071 (n-up-filling (ps-n-up-filling)))
4072 (and ps-n-up-on
(setq tumble
(not tumble
)))
4075 "%%Title: " (buffer-name) ; Take job name from name of
4076 ; first buffer printed
4077 "\n%%Creator: " (user-full-name)
4078 " (using ps-print v" ps-print-version
4079 ")\n%%CreationDate: "
4080 (time-stamp-hh:mm
:ss
) " " (time-stamp-mon-dd-yyyy)
4082 (if ps-landscape-mode
"Landscape" "Portrait")
4083 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
4084 (mapconcat 'identity
4085 (ps-remove-duplicates
4086 (append (ps-fonts 'ps-font-for-text
)
4087 (list (ps-font 'ps-font-for-header
'normal
)
4088 (ps-font 'ps-font-for-header
'bold
))))
4090 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions
)
4091 (format " %d" (round (ps-page-dimensions-get-width dimensions
)))
4092 (format " %d" (round (ps-page-dimensions-get-height dimensions
)))
4093 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
4095 (if tumble
" duplex(tumble)\n" " duplex\n")
4098 (ps-insert-string ps-print-prologue-header
)
4100 (ps-output "%%EndComments\n%%BeginDefaults\n%%PageMedia: "
4101 (ps-page-dimensions-get-media dimensions
)
4102 "\n%%EndDefaults\n\n%%BeginPrologue\n\n"
4103 "/languagelevel where{pop}{/languagelevel 1 def}ifelse\n"
4104 (format "/ErrorMessage %s def\n\n"
4105 (or (cdr (assoc ps-error-handler-message
4106 ps-error-handler-alist
))
4109 "\n%%BeginProcSet: UserDefinedPrologue\n\n")
4111 (ps-insert-string ps-user-defined-prologue
)
4113 (ps-output "\n%%EndProcSet\n\n")
4115 (ps-output-boolean "LandscapeMode "
4116 (or ps-landscape-mode
4117 (eq (ps-n-up-landscape n-up
) 'pag
)))
4118 (ps-output-boolean "UpsideDown " ps-print-upside-down
)
4119 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns
)
4121 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height
)
4122 (format "/PrintPageWidth %s def\n"
4123 (- (* (+ ps-print-width ps-inter-column
)
4124 ps-number-of-columns
)
4126 (format "/PrintWidth %s def\n" ps-print-width
)
4127 (format "/PrintHeight %s def\n" ps-print-height
)
4129 (format "/LeftMargin %s def\n" ps-left-margin
)
4130 (format "/RightMargin %s def\n" ps-right-margin
)
4131 (format "/InterColumn %s def\n" ps-inter-column
)
4133 (format "/BottomMargin %s def\n" ps-bottom-margin
)
4134 (format "/TopMargin %s def\n" ps-top-margin
) ; not used
4135 (format "/HeaderOffset %s def\n" ps-header-offset
)
4136 (format "/HeaderPad %s def\n" ps-header-pad
))
4138 (ps-output-boolean "PrintHeader " ps-print-header
)
4139 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header
)
4140 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame
)
4141 (ps-output-boolean "SwitchHeader " (if (eq ps-switch-header
'duplex
)
4144 (ps-output-boolean "ShowNofN " ps-show-n-of-n
)
4145 (ps-output-boolean "DuplexValue " ps-spool-duplex
)
4146 (ps-output-boolean "TumbleValue " tumble
)
4148 (let ((line-height (ps-line-height 'ps-font-for-text
)))
4149 (ps-output (format "/LineHeight %s def\n" line-height
)
4150 (format "/LinesPerColumn %d def\n"
4151 (round (/ (+ ps-print-height
4152 (* line-height
0.45))
4155 (ps-output-boolean "WarnPaperSize " ps-warn-paper-type
)
4156 (ps-output-boolean "Zebra " ps-zebra-stripes
)
4157 (ps-output-boolean "ZebraFollow " ps-zebra-stripe-follow
)
4158 (ps-output-boolean "PrintLineNumber " ps-line-number
)
4159 (ps-output-boolean "SyncLineZebra " (not (integerp ps-line-number-step
)))
4160 (ps-output (format "/PrintLineStep %d def\n"
4161 (if (integerp ps-line-number-step
)
4163 ps-zebra-stripe-height
))
4164 (format "/PrintLineStart %d def\n" ps-line-number-start
)
4165 (format "/ZebraHeight %d def\n" ps-zebra-stripe-height
)
4167 (ps-format-color ps-zebra-color
0.95)
4168 "def\n/BackgroundColor "
4169 (ps-format-color ps-default-bg
1.0)
4170 "def\n/UseSetpagedevice "
4171 (if (eq ps-spool-config
'setpagedevice
)
4172 "/setpagedevice where{pop languagelevel 2 eq}{false}ifelse"
4174 " def\n\n/PageWidth "
4175 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
4176 (format "/N-Up %d def\n" ps-n-up-printing
))
4177 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up
) t
))
4178 (ps-output-boolean "N-Up-Border " ps-n-up-border-p
)
4179 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up
))
4180 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up
))
4181 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up
))
4182 (format "/N-Up-Margin %s def\n" ps-n-up-margin
)
4184 (if ps-landscape-mode
4185 (ps-n-up-end n-up-filling
)
4186 (ps-n-up-repeat n-up-filling
))
4188 (if ps-landscape-mode
4189 (ps-n-up-repeat n-up-filling
)
4190 (ps-n-up-end n-up-filling
))
4191 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling
)
4192 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling
)
4193 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling
)
4194 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling
)
4195 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling
)
4196 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling
) " def\n")
4198 (ps-background-text)
4199 (ps-background-image)
4200 (setq ps-background-all-pages
(nreverse ps-background-all-pages
)
4201 ps-background-pages
(nreverse ps-background-pages
))
4203 (ps-output "\n" ps-print-prologue-1
)
4205 (ps-output "\n/printGlobalBackground {\n")
4206 (ps-output-list ps-background-all-pages
)
4207 (ps-output "} def\n/printLocalBackground {\n} def\n")
4210 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
4211 ps-header-title-font-size-internal
4212 (ps-font 'ps-font-for-header
'bold
))
4213 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
4214 ps-header-font-size-internal
4215 (ps-font 'ps-font-for-header
'normal
)))
4217 (ps-output "\n" ps-print-prologue-2
"\n")
4220 (let ((font (ps-font-alist 'ps-font-for-text
))
4223 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
4225 ps-font-size-internal
4226 (ps-font 'ps-font-for-text
(car (car font
)))))
4227 (setq font
(cdr font
)
4230 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database
))))
4231 (ps-output (format "/SpaceWidthRatio %f def\n"
4232 (/ (ps-lookup 'space-width
) (ps-lookup 'size
)))))
4234 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
4235 (unless (eq ps-spool-config
'lpr-switches
)
4236 (ps-output "\n%%BeginFeature: *Duplex "
4237 (ps-boolean-capitalized ps-spool-duplex
)
4239 (ps-boolean-capitalized tumble
)
4241 ps-print-duplex-feature
4242 "\n%%EndFeature\n")))
4243 (ps-output "\n%%BeginFeature: *ManualFeed "
4244 (ps-boolean-capitalized ps-manual-feed
)
4245 "\nBMark /ManualFeed "
4246 (ps-boolean-constant ps-manual-feed
)
4247 " EMark setpagedevice\n%%EndFeature\n"
4248 "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n")
4249 (and ps-banner-page-when-duplexing
4250 (ps-output "\n%%Page: banner 0\nsave showpage restore\n")))
4253 (defun ps-format-color (color &optional default
)
4254 (let ((the-color (if (stringp color
)
4255 (ps-color-scale color
)
4257 (if (and the-color
(listp the-color
))
4259 (format ps-color-format
4264 (ps-float-format (if (numberp the-color
) the-color default
)))))
4267 (defun ps-insert-string (prologue)
4268 (let ((str (if (functionp prologue
)
4275 (defun ps-boolean-capitalized (bool)
4276 (if bool
"True" "False"))
4279 (defun ps-boolean-constant (bool)
4280 (if bool
"true" "false"))
4283 (defun ps-header-dirpart ()
4284 (let ((fname (buffer-file-name)))
4286 (if (string-equal (buffer-name) (file-name-nondirectory fname
))
4287 (abbreviate-file-name (file-name-directory fname
))
4292 (defun ps-get-buffer-name ()
4294 ;; Indulge Jim this little easter egg:
4295 ((string= (buffer-name) "ps-print.el")
4296 "Hey, Cool! It's ps-print.el!!!")
4297 ;; Indulge Jack this other little easter egg:
4298 ((string= (buffer-name) "sokoban.el")
4299 "Super! C'est sokoban.el!")
4301 (and ps-printing-region-p
"Subset of: ")
4303 (and (buffer-modified-p) " (unsaved)")))))
4306 (defun ps-get-font-size (font-sym)
4307 (let ((font-size (symbol-value font-sym
)))
4308 (cond ((numberp font-size
)
4310 ((and (consp font-size
)
4311 (numberp (car font-size
))
4312 (numberp (cdr font-size
)))
4313 (if ps-landscape-mode
4317 (error "Invalid font size `%S' for `%S'" font-size font-sym
)))))
4320 (defun ps-begin-job ()
4321 (let ((last-char (aref ps-postscript-code-directory
4322 (1- (length ps-postscript-code-directory
)))))
4323 (or (eq last-char ?
/)
4324 (and ps-windows-system
(eq last-char ?
\\))
4325 (setq ps-postscript-code-directory
4326 (concat ps-postscript-code-directory
"/"))))
4327 (or (equal ps-mark-code-directory ps-postscript-code-directory
)
4328 (setq ps-print-prologue-0
(ps-prologue-file 0)
4329 ps-print-prologue-1
(ps-prologue-file 1)
4330 ps-print-prologue-2
(ps-prologue-file 2)
4331 ps-print-duplex-feature
(ps-prologue-file 3)
4332 ps-mark-code-directory ps-postscript-code-directory
))
4333 (or (listp ps-use-face-background
)
4334 (setq ps-use-face-background t
))
4335 (and (integerp ps-line-number-step
)
4336 (<= ps-line-number-step
0)
4337 (setq ps-line-number-step
1))
4338 (setq ps-n-up-on
(> ps-n-up-printing
1)
4339 ps-line-number-start
(max 1 (min ps-line-number-start
4340 (if (integerp ps-line-number-step
)
4342 ps-zebra-stripe-height
))))
4344 (set-buffer ps-spool-buffer
)
4345 (goto-char (point-max))
4346 (and (re-search-backward "^%%Trailer$" nil t
)
4347 (delete-region (match-beginning 0) (point-max))))
4348 (setq ps-showline-count
(car ps-printing-region
)
4350 ps-font-size-internal
(ps-get-font-size 'ps-font-size
)
4351 ps-header-font-size-internal
(ps-get-font-size 'ps-header-font-size
)
4352 ps-header-title-font-size-internal
4353 (ps-get-font-size 'ps-header-title-font-size
)
4354 ps-control-or-escape-regexp
4355 (cond ((eq ps-print-control-characters
'8-bit
)
4356 (string-as-unibyte "[\000-\037\177-\377]"))
4357 ((eq ps-print-control-characters
'control-8-bit
)
4358 (string-as-unibyte "[\000-\037\177-\237]"))
4359 ((eq ps-print-control-characters
'control
)
4362 ps-default-foreground
(ps-rgb-color ps-default-fg
0.0)
4363 ps-default-color
(and ps-print-color-p ps-default-foreground
)
4364 ps-current-color ps-default-color
4365 ;; Set the color scale. We do it here instead of in the defvar so
4366 ;; that ps-print can be dumped into emacs. This expression can't be
4367 ;; evaluated at dump-time because X isn't initialized.
4368 ps-color-p
(and ps-print-color-p
(ps-color-device))
4369 ps-print-color-scale
(if ps-color-p
4370 (float (car (ps-color-values "white")))
4374 (defun ps-rgb-color (color default
)
4375 (cond ((and color
(listp color
)) color
)
4376 ((stringp color
) (ps-color-scale color
))
4377 ((numberp color
) (list color color color
))
4378 (t (list default default default
))
4382 (defmacro ps-page-number
()
4383 `(1+ (/ (1- ps-page-count
) ps-number-of-columns
)))
4385 (defun ps-end-file (needs-begin-file)
4387 ;; Back to the PS output buffer to set the last page n-up printing
4389 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing
))
4391 (set-buffer ps-spool-buffer
)
4392 (goto-char (point-max))
4393 (and (> pages-per-sheet
0)
4394 (re-search-backward "^[0-9]+ BeginSheet$" nil t
)
4395 (replace-match (format "%d BeginSheet" pages-per-sheet
) t
))))
4397 (and ps-spool-duplex
(= (mod ps-page-order
2) 1)
4399 ;; Set end of PostScript file
4400 (ps-output "EndSheet\n\n%%Trailer\n%%Pages: "
4402 (if (and needs-begin-file ps-banner-page-when-duplexing
)
4405 "\n\nEndDoc\n\n%%EOF\n"))
4408 (defun ps-next-page ()
4414 (defun ps-header-sheet ()
4415 ;; Print only when a new sheet begins.
4416 (setq ps-page-postscript
(1+ ps-page-postscript
)
4417 ps-page-order
(1+ ps-page-order
))
4418 (and (> ps-page-order
1)
4419 (ps-output "EndSheet\n"))
4420 (ps-output (if ps-n-up-on
4421 (format "\n%%%%Page: (%d \\(%d\\)) %d\n"
4422 ps-page-order ps-page-postscript ps-page-order
)
4423 (format "\n%%%%Page: %d %d\n"
4424 ps-page-postscript ps-page-order
))
4425 (format "%d BeginSheet\nBeginDSCPage\n" ps-n-up-printing
)))
4428 (defsubst ps-header-page
()
4429 ;; set total line and page number when printing has finished
4430 ;; (see `ps-generate')
4433 (zerop (mod ps-page-count ps-number-of-columns
))
4434 (setq ps-page-count
(1+ ps-page-count
)))
4436 (if (zerop (mod ps-page-postscript ps-n-up-printing
))
4437 ;; Print only when a new sheet begins.
4440 'ps-print-begin-sheet-hook
)
4441 ;; Print only when a new page begins.
4442 (setq ps-page-postscript
(1+ ps-page-postscript
))
4443 (ps-output "BeginDSCPage\n")
4444 'ps-print-begin-page-hook
)
4445 (ps-background ps-page-postscript
))
4446 ;; Print only when a new column begins.
4447 (ps-output "BeginDSCPage\n")
4448 'ps-print-begin-column-hook
)))
4450 (defun ps-begin-page ()
4451 (ps-get-page-dimensions)
4452 (setq ps-width-remaining ps-print-width
4453 ps-height-remaining ps-print-height
)
4457 (ps-output (format "/LineNumber %d def\n" ps-showline-count
)
4458 (format "/PageNumber %d def\n" (if ps-print-only-one-header
4462 (when ps-print-header
4463 (ps-generate-header "HeaderLinesLeft" ps-left-header
)
4464 (ps-generate-header "HeaderLinesRight" ps-right-header
)
4465 (ps-output (format "%d SetHeaderLines\n" ps-header-lines
)))
4467 (ps-output "BeginPage\n")
4468 (ps-set-font ps-current-font
)
4469 (ps-set-bg ps-current-bg
)
4470 (ps-set-color ps-current-color
)
4471 (ps-mule-begin-page))
4473 (defun ps-end-page ()
4474 (ps-output "EndPage\nEndDSCPage\n"))
4476 (defun ps-dummy-page ()
4477 (let ((ps-n-up-printing 0))
4479 (ps-output "/PrintHeader false def
4481 /PrintLineNumber false def
4485 (setq ps-page-postscript ps-n-up-printing
))
4487 (defun ps-next-line ()
4488 (setq ps-showline-count
(1+ ps-showline-count
))
4489 (let ((lh (ps-line-height 'ps-font-for-text
)))
4490 (if (< ps-height-remaining lh
)
4492 (setq ps-width-remaining ps-print-width
4493 ps-height-remaining
(- ps-height-remaining lh
))
4494 (ps-output "HL\n"))))
4496 (defun ps-continue-line ()
4497 (let ((lh (ps-line-height 'ps-font-for-text
)))
4498 (if (< ps-height-remaining lh
)
4500 (setq ps-width-remaining ps-print-width
4501 ps-height-remaining
(- ps-height-remaining lh
))
4502 (ps-output "SL\n"))))
4504 (defun ps-find-wrappoint (from to char-width
)
4505 (let ((avail (truncate (/ ps-width-remaining char-width
)))
4508 (cons to
(* todo char-width
))
4509 (cons (+ from avail
) ps-width-remaining
))))
4511 (defun ps-basic-plot-string (from to
&optional bg-color
)
4512 (let* ((wrappoint (ps-find-wrappoint from to
4513 (ps-avg-char-width 'ps-font-for-text
)))
4514 (to (car wrappoint
))
4515 (string (buffer-substring-no-properties from to
)))
4516 (ps-mule-prepare-ascii-font string
)
4517 (ps-output-string string
)
4521 (defun ps-basic-plot-whitespace (from to
&optional bg-color
)
4522 (let* ((wrappoint (ps-find-wrappoint from to
4523 (ps-space-width 'ps-font-for-text
)))
4524 (to (car wrappoint
)))
4525 (ps-output (format "%d W\n" (- to from
)))
4528 (defun ps-plot (plotfunc from to
&optional bg-color
)
4530 (let* ((wrappoint (funcall plotfunc from to bg-color
))
4531 (plotted-to (car wrappoint
))
4532 (plotted-width (cdr wrappoint
)))
4533 (setq from plotted-to
4534 ps-width-remaining
(- ps-width-remaining plotted-width
))
4536 (ps-continue-line))))
4537 (if ps-razzle-dazzle
4538 (let* ((q-todo (- (point-max) (point-min)))
4539 (q-done (- (point) (point-min)))
4540 (chunkfrac (/ q-todo
8))
4541 (chunksize (min chunkfrac
1000)))
4542 (if (> (- q-done ps-razchunk
) chunksize
)
4544 (setq ps-razchunk q-done
)
4545 (message "Formatting...%3d%%"
4547 (/ (* 100 q-done
) q-todo
)
4548 (/ q-done
(/ q-todo
100)))
4551 (defvar ps-last-font nil
)
4553 (defun ps-set-font (font)
4554 (setq ps-last-font
(format "f%d" (setq ps-current-font font
)))
4555 (ps-output (format "/%s F\n" ps-last-font
)))
4557 (defun ps-set-bg (color)
4558 (if (setq ps-current-bg color
)
4559 (ps-output (format ps-color-format
4560 (nth 0 color
) (nth 1 color
) (nth 2 color
))
4562 (ps-output "false BG\n")))
4564 (defun ps-set-color (color)
4565 (setq ps-current-color
(or color ps-default-foreground
))
4566 (ps-output (format ps-color-format
4567 (nth 0 ps-current-color
)
4568 (nth 1 ps-current-color
) (nth 2 ps-current-color
))
4572 (defvar ps-current-effect
0)
4575 (defun ps-plot-region (from to font
&optional fg-color bg-color effects
)
4576 (if (not (equal font ps-current-font
))
4579 ;; Specify a foreground color only if one's specified and it's
4580 ;; different than the current.
4581 (if (not (equal fg-color ps-current-color
))
4582 (ps-set-color fg-color
))
4584 (if (not (equal bg-color ps-current-bg
))
4585 (ps-set-bg bg-color
))
4587 ;; Specify effects (underline, overline, box, etc)
4589 ((not (integerp effects
))
4590 (ps-output "0 EF\n")
4591 (setq ps-current-effect
0))
4592 ((/= effects ps-current-effect
)
4593 (ps-output (number-to-string effects
) " EF\n")
4594 (setq ps-current-effect effects
)))
4596 ;; Starting at the beginning of the specified region...
4600 ;; ...break the region up into chunks separated by tabs, linefeeds,
4601 ;; pagefeeds, control characters, and plot each chunk.
4603 (if (re-search-forward ps-control-or-escape-regexp to t
)
4604 ;; region with some control characters or some multi-byte characters
4605 (let* ((match-point (match-beginning 0))
4606 (match (char-after match-point
))
4607 (composition (find-composition from
(1+ match-point
))))
4609 (if (and (nth 2 composition
)
4610 (<= (car composition
) match-point
))
4612 (setq match-point
(car composition
)
4614 (goto-char (nth 1 composition
)))
4615 (setq composition nil
)))
4616 (when (< from match-point
)
4617 (ps-mule-set-ascii-font)
4618 (ps-plot 'ps-basic-plot-string from match-point bg-color
))
4620 ((= match ?
\t) ; tab
4621 (let ((linestart (line-beginning-position)))
4623 (setq from
(+ linestart
(current-column)))
4624 (when (re-search-forward "[ \t]+" to t
)
4625 (ps-mule-set-ascii-font)
4626 (ps-plot 'ps-basic-plot-whitespace
4627 from
(+ linestart
(current-column))
4630 ((= match ?
\n) ; newline
4633 ((= match ?
\f) ; form feed
4634 ;; do not skip page if previous character is NEWLINE and
4635 ;; it is a beginning of page.
4636 (or (and (= (char-after (1- match-point
)) ?
\n)
4637 (= ps-height-remaining ps-print-height
))
4640 (composition ; a composite sequence
4641 (ps-plot 'ps-mule-plot-composition match-point
(point) bg-color
))
4643 ; characters from ^@ to ^_ and
4644 ((> match
255) ; a multi-byte character
4645 (let* ((charset (char-charset match
))
4646 (composition (find-composition match-point to
))
4647 (stop (if (nth 2 composition
) (car composition
) to
)))
4648 (or (eq charset
'composition
)
4649 (while (and (< (point) stop
) (eq (charset-after) charset
))
4651 (ps-plot 'ps-mule-plot-string match-point
(point) bg-color
)))
4653 (t ; characters from 127 to 255
4654 (ps-control-character match
)))
4655 (setq from
(point)))
4656 ;; region without control characters nor multi-byte characters
4657 (ps-mule-set-ascii-font)
4658 (ps-plot 'ps-basic-plot-string from to bg-color
)
4661 (defvar ps-string-control-codes
4662 (let ((table (make-vector 256 nil
))
4664 ;; control character
4665 (while (<= char ?
\037)
4666 (aset table char
(format "^%c" (+ char ?
@)))
4667 (setq char
(1+ char
)))
4668 ;; printable character
4669 (while (< char ?
\177)
4670 (aset table char
(format "%c" char
))
4671 (setq char
(1+ char
)))
4673 (aset table char
"^?")
4675 (while (<= (setq char
(1+ char
)) ?
\377)
4676 (aset table char
(format "\\%o" char
)))
4678 "Vector used to map characters to a printable string.")
4680 (defun ps-control-character (char)
4681 (let* ((str (aref ps-string-control-codes char
))
4685 (char-width (ps-avg-char-width 'ps-font-for-text
))
4686 (wrappoint (ps-find-wrappoint from to char-width
)))
4687 (if (< (car wrappoint
) to
)
4689 (setq ps-width-remaining
(- ps-width-remaining
(* len char-width
)))
4690 (ps-mule-prepare-ascii-font str
)
4691 (ps-output-string str
)
4692 (ps-output " S\n")))
4694 (defun ps-color-scale (color)
4695 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
4696 (mapcar #'(lambda (value) (/ value ps-print-color-scale
))
4697 (ps-color-values color
)))
4700 (defun ps-xemacs-color-name (color)
4701 (if (color-specifier-p color
)
4706 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4708 (defun ps-color-values (x-color)
4709 (if (fboundp 'x-color-values
)
4710 (x-color-values x-color
)
4711 (error "No available function to determine X color values.")))
4716 (defun ps-color-values (x-color)
4717 (let ((color (ps-xemacs-color-name x-color
)))
4719 ((fboundp 'x-color-values
)
4720 (x-color-values color
))
4721 ((and (fboundp 'color-instance-rgb-components
)
4723 (color-instance-rgb-components
4724 (if (color-instance-p x-color
)
4726 (make-color-instance color
))))
4728 (error "No available function to determine X color values.")))))
4732 (defun ps-face-attributes (face)
4733 "Return face attribute vector.
4735 If FACE is not in `ps-print-face-extension-alist' or in
4736 `ps-print-face-alist', insert it on `ps-print-face-alist' and
4737 return the attribute vector.
4739 If FACE is not a valid face name, it is used default face."
4740 (cdr (or (assq face ps-print-face-extension-alist
)
4741 (assq face ps-print-face-alist
)
4742 (let* ((the-face (if (facep face
) face
'default
))
4743 (new-face (ps-screen-to-bit-face the-face
)))
4744 (or (and (eq the-face
'default
)
4745 (assq the-face ps-print-face-alist
))
4746 (setq ps-print-face-alist
(cons new-face ps-print-face-alist
)))
4750 (defun ps-face-background (face background
)
4751 (and (or (eq ps-use-face-background t
)
4752 (cond ((symbolp face
)
4753 (memq face ps-use-face-background
))
4757 (if (memq (car face
) ps-use-face-background
)
4760 (setq face
(cdr face
))))
4768 (defun ps-face-attribute-list (face-or-list)
4769 (if (listp face-or-list
)
4772 foreground background face-attr face
)
4774 (setq face
(car face-or-list
)
4775 face-or-list
(cdr face-or-list
)
4776 face-attr
(ps-face-attributes face
)
4777 effects
(logior effects
(aref face-attr
0)))
4778 (or foreground
(setq foreground
(aref face-attr
1)))
4780 (setq background
(ps-face-background face
(aref face-attr
2)))))
4781 (vector effects foreground background
))
4783 (ps-face-attributes face-or-list
)))
4786 (defconst ps-font-type
(vector nil
'bold
'italic
'bold-italic
))
4789 (defun ps-plot-with-face (from to face
)
4791 ((null face
) ; print text with null face
4792 (ps-plot-region from to
0))
4793 ((eq face
'emacs--invisible--face
)) ; skip invisible text!!!
4794 (t ; otherwise, text has a valid face
4795 (let* ((face-bit (ps-face-attribute-list face
))
4796 (effect (aref face-bit
0))
4797 (foreground (aref face-bit
1))
4798 (background (ps-face-background face
(aref face-bit
2)))
4799 (fg-color (if (and ps-color-p foreground
)
4800 (ps-color-scale foreground
)
4802 (bg-color (and ps-color-p background
4803 (ps-color-scale background
))))
4806 (ps-font-number 'ps-font-for-text
4807 (or (aref ps-font-type
(logand effect
3))
4809 fg-color bg-color
(lsh effect -
2)))))
4813 (defun ps-xemacs-face-kind-p (face kind kind-regex
)
4814 (let* ((frame-font (or (face-font-instance face
)
4815 (face-font-instance 'default
)))
4816 (kind-cons (and frame-font
4818 (font-instance-properties frame-font
))))
4819 (kind-spec (cdr-safe kind-cons
))
4820 (case-fold-search t
))
4821 (and kind-spec
(string-match kind-regex kind-spec
))))
4824 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4826 (defalias 'ps-face-foreground-name
'face-foreground
)
4827 (defalias 'ps-face-background-name
'face-background
)
4829 (defun ps-face-bold-p (face)
4830 (or (face-bold-p face
)
4831 (memq face ps-bold-faces
)))
4833 (defun ps-face-italic-p (face)
4834 (or (face-italic-p face
)
4835 (memq face ps-italic-faces
)))
4840 (defun ps-face-foreground-name (face)
4841 (ps-xemacs-color-name (face-foreground face
)))
4843 (defun ps-face-background-name (face)
4844 (ps-xemacs-color-name (face-background face
)))
4846 (defun ps-face-bold-p (face)
4847 (or (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold")
4848 (memq face ps-bold-faces
))) ; Kludge-compatible
4850 (defun ps-face-italic-p (face)
4851 (or (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o")
4852 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o")
4853 (memq face ps-italic-faces
))) ; Kludge-compatible
4857 (defun ps-face-underlined-p (face)
4858 (or (face-underline-p face
)
4859 (memq face ps-underlined-faces
)))
4862 ;; Ensure that face-list is fbound.
4863 (or (fboundp 'face-list
) (defalias 'face-list
'list-faces
))
4866 (defun ps-build-reference-face-lists ()
4867 ;; Ensure that face database is updated with faces on
4868 ;; `font-lock-face-attributes' (obsolete stuff)
4869 (ps-font-lock-face-attributes)
4870 ;; Now, rebuild reference face lists
4871 (setq ps-print-face-alist nil
)
4872 (if ps-auto-font-detect
4873 (mapcar 'ps-map-face
(face-list))
4874 (mapcar 'ps-set-face-bold ps-bold-faces
)
4875 (mapcar 'ps-set-face-italic ps-italic-faces
)
4876 (mapcar 'ps-set-face-underline ps-underlined-faces
))
4877 (setq ps-build-face-reference nil
))
4880 (defun ps-set-face-bold (face)
4881 (ps-set-face-attribute face
1))
4883 (defun ps-set-face-italic (face)
4884 (ps-set-face-attribute face
2))
4886 (defun ps-set-face-underline (face)
4887 (ps-set-face-attribute face
4))
4890 (defun ps-set-face-attribute (face effect
)
4891 (let ((face-bit (cdr (ps-map-face face
))))
4892 (aset face-bit
0 (logior (aref face-bit
0) effect
))))
4895 (defun ps-map-face (face)
4896 (let* ((face-map (ps-screen-to-bit-face face
))
4897 (ps-face-bit (cdr (assq (car face-map
) ps-print-face-alist
))))
4899 ;; if face exists, merge both
4900 (let ((face-bit (cdr face-map
)))
4901 (aset ps-face-bit
0 (logior (aref ps-face-bit
0) (aref face-bit
0)))
4902 (or (aref ps-face-bit
1) (aset ps-face-bit
1 (aref face-bit
1)))
4903 (or (aref ps-face-bit
2) (aset ps-face-bit
2 (aref face-bit
2))))
4904 ;; if face does not exist, insert it
4905 (setq ps-print-face-alist
(cons face-map ps-print-face-alist
)))
4909 (defun ps-screen-to-bit-face (face)
4911 (vector (logior (if (ps-face-bold-p face
) 1 0) ; bold
4912 (if (ps-face-italic-p face
) 2 0) ; italic
4913 (if (ps-face-underlined-p face
) 4 0)) ; underline
4914 (ps-face-foreground-name face
)
4915 (ps-face-background-name face
))))
4918 (cond ((not (eq ps-print-emacs-type
'emacs
))
4922 (defun ps-mapper (extent list
)
4923 (nconc list
(list (list (extent-start-position extent
) 'push extent
)
4924 (list (extent-end-position extent
) 'pull extent
)))
4927 (defun ps-extent-sorter (a b
)
4928 (< (extent-priority a
) (extent-priority b
)))
4932 (defun ps-print-ensure-fontified (start end
)
4933 (and (boundp 'lazy-lock-mode
) (symbol-value 'lazy-lock-mode
)
4934 (lazy-lock-fontify-region start end
)))
4936 (defun ps-generate-postscript-with-faces (from to
)
4937 ;; Some initialization...
4938 (setq ps-current-effect
0)
4940 ;; Build the reference lists of faces if necessary.
4941 (when (or ps-always-build-face-reference
4942 ps-build-face-reference
)
4943 (message "Collecting face information...")
4944 (ps-build-reference-face-lists))
4945 ;; Generate some PostScript.
4947 (narrow-to-region from to
)
4948 (ps-print-ensure-fontified from to
)
4949 (let ((face 'default
)
4952 ((memq ps-print-emacs-type
'(xemacs lucid
))
4953 ;; Build the list of extents...
4954 (let ((a (cons 'dummy nil
))
4955 record type extent extent-list
)
4956 (map-extents 'ps-mapper nil from to a
)
4957 (setq a
(sort (cdr a
) 'car-less-than-car
)
4960 ;; Loop through the extents...
4962 (setq record
(car a
)
4964 position
(car record
)
4970 extent
(car record
))
4972 ;; Plot up to this record.
4973 ;; XEmacs 19.12: for some reason, we're getting into a
4974 ;; situation in which some of the records have
4975 ;; positions less than 'from'. Since we've narrowed
4976 ;; the buffer, this'll generate errors. This is a
4977 ;; hack, but don't call ps-plot-with-face unless from >
4979 (and (>= from
(point-min)) (<= position
(point-max))
4980 (ps-plot-with-face from position face
))
4984 (and (extent-face extent
)
4985 (setq extent-list
(sort (cons extent extent-list
)
4986 'ps-extent-sorter
))))
4989 (setq extent-list
(sort (delq extent extent-list
)
4990 'ps-extent-sorter
))))
4992 (setq face
(if extent-list
4993 (extent-face (car extent-list
))
4998 ((eq ps-print-emacs-type
'emacs
)
4999 (let ((property-change from
)
5000 (overlay-change from
)
5001 (save-buffer-invisibility-spec buffer-invisibility-spec
)
5002 (buffer-invisibility-spec nil
))
5004 (and (< property-change to
) ; Don't search for property change
5005 ; unless previous search succeeded.
5006 (setq property-change
(next-property-change from nil to
)))
5007 (and (< overlay-change to
) ; Don't search for overlay change
5008 ; unless previous search succeeded.
5009 (setq overlay-change
(min (next-overlay-change from
) to
)))
5010 (setq position
(min property-change overlay-change
))
5011 ;; The code below is not quite correct,
5012 ;; because a non-nil overlay invisible property
5013 ;; which is inactive according to the current value
5014 ;; of buffer-invisibility-spec nonetheless overrides
5015 ;; a face text property.
5017 (cond ((let ((prop (get-text-property from
'invisible
)))
5018 ;; Decide whether this invisible property
5019 ;; really makes the text invisible.
5020 (if (eq save-buffer-invisibility-spec t
)
5022 (or (memq prop save-buffer-invisibility-spec
)
5023 (assq prop save-buffer-invisibility-spec
))))
5024 'emacs--invisible--face
)
5025 ((get-text-property from
'face
))
5027 (let ((overlays (overlays-at from
))
5028 (face-priority -
1)) ; text-property
5029 (while (and overlays
5030 (not (eq face
'emacs--invisible--face
)))
5031 (let* ((overlay (car overlays
))
5032 (overlay-invisible (overlay-get overlay
'invisible
))
5033 (overlay-priority (or (overlay-get overlay
'priority
)
5035 (and (> overlay-priority face-priority
)
5037 (cond ((if (eq save-buffer-invisibility-spec t
)
5038 (not (null overlay-invisible
))
5039 (or (memq overlay-invisible
5040 save-buffer-invisibility-spec
)
5041 (assq overlay-invisible
5042 save-buffer-invisibility-spec
)))
5043 'emacs--invisible--face
)
5044 ((overlay-get overlay
'face
))
5046 face-priority overlay-priority
)))
5047 (setq overlays
(cdr overlays
))))
5048 ;; Plot up to this record.
5049 (ps-plot-with-face from position face
)
5050 (setq from position
)))))
5051 (ps-plot-with-face from to face
))))
5053 (defun ps-generate-postscript (from to
)
5054 (ps-plot-region from to
0 nil
))
5056 (defun ps-generate (buffer from to genfunc
)
5058 (let ((from (min to from
))
5060 ;; This avoids trouble if chars with read-only properties
5061 ;; are copied into ps-spool-buffer.
5062 (inhibit-read-only t
))
5064 (narrow-to-region from to
)
5065 (and ps-razzle-dazzle
5066 (message "Formatting...%3d%%" (setq ps-razchunk
0)))
5067 (setq ps-source-buffer buffer
5068 ps-spool-buffer
(get-buffer-create ps-spool-buffer-name
))
5069 (ps-init-output-queue)
5070 (let (safe-marker completed-safely needs-begin-file
)
5073 (set-buffer ps-spool-buffer
)
5074 (set-buffer-multibyte nil
)
5076 ;; Get a marker and make it point to the current end of the
5077 ;; buffer, If an error occurs, we'll delete everything from
5078 ;; the end of this marker onwards.
5079 (setq safe-marker
(make-marker))
5080 (set-marker safe-marker
(point-max))
5082 (goto-char (point-min))
5083 (or (looking-at (regexp-quote ps-adobe-tag
))
5084 (setq needs-begin-file t
))
5086 (set-buffer ps-source-buffer
)
5088 (when needs-begin-file
5090 (ps-mule-initialize))
5091 (ps-mule-begin-job from to
)
5093 (set-buffer ps-source-buffer
)
5094 (funcall genfunc from to
)
5097 (ps-end-file needs-begin-file
)
5100 ;; Setting this variable tells the unwind form that the
5101 ;; the PostScript was generated without error.
5102 (setq completed-safely t
))
5104 ;; Unwind form: If some bad mojo occurred while generating
5105 ;; PostScript, delete all the PostScript that was generated.
5106 ;; This protects the previously spooled files from getting
5108 (and (markerp safe-marker
) (not completed-safely
)
5110 (set-buffer ps-spool-buffer
)
5111 (delete-region (marker-position safe-marker
) (point-max))))))
5113 (and ps-razzle-dazzle
(message "Formatting...done"))))))
5116 (defun ps-end-job ()
5118 (let ((total-lines (cdr ps-printing-region
))
5119 (total-pages (if ps-print-only-one-header
5123 (set-buffer ps-spool-buffer
)
5124 ;; Back to the PS output buffer to set the page count
5125 (goto-char (point-min))
5126 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t
)
5127 (replace-match (format "/Lines %d def\n/PageCount %d def"
5128 total-lines total-pages
) t
))))
5131 (defvar ps-printer-name-option
5132 (cond (ps-windows-system
5140 ;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
5141 (defun ps-do-despool (filename)
5142 (if (or (not (boundp 'ps-spool-buffer
))
5143 (not (symbol-value 'ps-spool-buffer
)))
5144 (message "No spooled PostScript to print")
5147 (and ps-razzle-dazzle
(message "Saving..."))
5148 (set-buffer ps-spool-buffer
)
5149 (setq filename
(expand-file-name filename
))
5150 (let ((coding-system-for-write 'raw-text-unix
))
5151 (write-region (point-min) (point-max) filename
))
5152 (and ps-razzle-dazzle
(message "Wrote %s" filename
)))
5153 ;; Else, spool to the printer
5154 (and ps-razzle-dazzle
(message "Printing..."))
5156 (set-buffer ps-spool-buffer
)
5157 (let* ((coding-system-for-write 'raw-text-unix
)
5158 (ps-printer-name (or ps-printer-name
5159 (and (boundp 'printer-name
)
5162 (append (and (stringp ps-printer-name
)
5163 (list (concat ps-printer-name-option
5166 (apply (or ps-print-region-function
'call-process-region
)
5167 (point-min) (point-max) ps-lpr-command nil
5168 (and (fboundp 'start-process
) 0)
5170 (ps-flatten-list ; dynamic evaluation
5171 (mapcar 'ps-eval-switch ps-lpr-switches
)))))
5172 (and ps-razzle-dazzle
(message "Printing...done")))
5173 (kill-buffer ps-spool-buffer
)))
5175 ;; Dynamic evaluation
5176 (defun ps-eval-switch (arg)
5177 (cond ((stringp arg
) arg
)
5178 ((functionp arg
) (apply arg nil
))
5179 ((symbolp arg
) (symbol-value arg
))
5180 ((consp arg
) (apply (car arg
) (cdr arg
)))
5183 ;; `ps-flatten-list' is defined here (copied from "message.el" and
5184 ;; enhanced to handle dotted pairs as well) until we can get some
5185 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
5187 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
5188 ;; => (a b c d e f g h i j)
5190 (defun ps-flatten-list (&rest list
)
5191 (ps-flatten-list-1 list
))
5193 (defun ps-flatten-list-1 (list)
5194 (cond ((null list
) nil
)
5195 ((consp list
) (append (ps-flatten-list-1 (car list
))
5196 (ps-flatten-list-1 (cdr list
))))
5199 (defun ps-kill-emacs-check ()
5201 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
5202 (buffer-modified-p ps-buffer
)
5203 (y-or-n-p "Unprinted PostScript waiting; print now? ")
5205 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
5206 (buffer-modified-p ps-buffer
)
5207 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
5208 (error "Unprinted PostScript"))))
5210 (cond ((fboundp 'add-hook
)
5211 (funcall 'add-hook
'kill-emacs-hook
'ps-kill-emacs-check
))
5213 (message "Won't override existing `kill-emacs-hook'"))
5215 (setq kill-emacs-hook
'ps-kill-emacs-check
)))
5218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5219 ;;; Sample Setup Code:
5222 ;; This stuff is for anybody that's brave enough to look this far,
5223 ;; and able to figure out how to use it. It isn't really part of
5224 ;; ps-print, but I'll leave it here in hopes it might be useful:
5226 ;; WARNING!!! The following code is *sample* code only.
5227 ;; Don't use it unless you understand what it does!
5229 (defmacro ps-prsc
()
5230 `(if (eq ps-print-emacs-type
'emacs
) [f22] 'f22))
5231 (defmacro ps-c-prsc ()
5232 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
5233 (defmacro ps-s-prsc ()
5234 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
5236 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
5237 ;; `ps-left-headers' specially for mail messages.
5238 (defun ps-rmail-mode-hook ()
5239 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
5240 (setq ps-header-lines 3
5242 ;; The left headers will display the message's subject, its
5243 ;; author, and the name of the folder it was in.
5244 '(ps-article-subject ps-article-author buffer-name)))
5246 ;; See `ps-gnus-print-article-from-summary'. This function does the
5247 ;; same thing for rmail.
5248 (defun ps-rmail-print-message-from-summary ()
5250 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
5252 ;; Used in `ps-rmail-print-article-from-summary',
5253 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
5254 (defun ps-print-message-from-summary (summary-buffer summary-default)
5255 (let ((ps-buf (or (and (boundp summary-buffer)
5256 (symbol-value summary-buffer))
5258 (and (get-buffer ps-buf)
5261 (ps-spool-buffer-with-faces)))))
5263 ;; Look in an article or mail message for the Subject: line. To be
5264 ;; placed in `ps-left-headers'.
5265 (defun ps-article-subject ()
5267 (goto-char (point-min))
5268 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
5269 (buffer-substring (match-beginning 1) (match-end 1))
5272 ;; Look in an article or mail message for the From: line. Sorta-kinda
5273 ;; understands RFC-822 addresses and can pull the real name out where
5274 ;; it's provided. To be placed in `ps-left-headers'.
5275 (defun ps-article-author ()
5277 (goto-char (point-min))
5278 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
5279 (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
5282 ;; Try first to match addresses that look like
5283 ;; thompson@wg2.waii.com (Jim Thompson)
5284 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
5285 (substring fromstring (match-beginning 1) (match-end 1)))
5287 ;; Next try to match addresses that look like
5288 ;; Jim Thompson <thompson@wg2.waii.com> or
5289 ;; "Jim Thompson" <thompson@wg2.waii.com>
5290 ((string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring)
5291 (substring fromstring (match-beginning 2) (match-end 2)))
5293 ;; Couldn't find a real name -- show the address instead.
5297 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
5298 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
5299 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
5300 ;; buffer enters that mode, so it would only work for the first time
5301 ;; we ran gnus. The second time, this hook wouldn't get set up. The
5302 ;; only alternative is `gnus-article-prepare-hook'.
5303 (defun ps-gnus-article-prepare-hook ()
5304 (setq ps-header-lines 3
5306 ;; The left headers will display the article's subject, its
5307 ;; author, and the newsgroup it was in.
5308 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
5310 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
5311 ;; `ps-left-headers' specially for mail messages.
5312 (defun ps-vm-mode-hook ()
5313 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
5314 (setq ps-header-lines 3
5316 ;; The left headers will display the message's subject, its
5317 ;; author, and the name of the folder it was in.
5318 '(ps-article-subject ps-article-author buffer-name)))
5320 ;; Every now and then I forget to switch from the *Summary* buffer to
5321 ;; the *Article* before hitting prsc, and a nicely formatted list of
5322 ;; article subjects shows up at the printer. This function, bound to
5323 ;; prsc for the gnus *Summary* buffer means I don't have to switch
5325 ;; sb: Updated for Gnus 5.
5326 (defun ps-gnus-print-article-from-summary ()
5328 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
5330 ;; See `ps-gnus-print-article-from-summary'. This function does the
5331 ;; same thing for vm.
5332 (defun ps-vm-print-message-from-summary ()
5334 (ps-print-message-from-summary 'vm-mail-buffer ""))
5336 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
5338 (defun ps-gnus-summary-setup ()
5339 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
5341 ;; Look in an article or mail message for the Subject: line. To be
5342 ;; placed in `ps-left-headers'.
5343 (defun ps-info-file ()
5345 (goto-char (point-min))
5346 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
5347 (buffer-substring (match-beginning 1) (match-end 1))
5350 ;; Look in an article or mail message for the Subject: line. To be
5351 ;; placed in `ps-left-headers'.
5352 (defun ps-info-node ()
5354 (goto-char (point-min))
5355 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
5356 (buffer-substring (match-beginning 1) (match-end 1))
5359 (defun ps-info-mode-hook ()
5360 (setq ps-left-header
5361 ;; The left headers will display the node name and file name.
5362 '(ps-info-node ps-info-file)))
5364 ;; WARNING! The following function is a *sample* only, and is *not*
5365 ;; meant to be used as a whole unless you understand what the effects
5366 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
5367 ;; I'd be very surprised if it was useful to *anybody*, without
5370 (defun ps-jts-ps-setup ()
5371 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
5372 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
5373 (global-set-key (ps-c-prsc) 'ps-despool)
5374 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
5375 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
5376 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
5377 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
5378 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
5379 (setq ps-spool-duplex t
5380 ps-print-color-p nil
5381 ps-lpr-command "lpr"
5382 ps-lpr-switches '("-Jjct,duplex_long"))
5385 ;; WARNING! The following function is a *sample* only, and is *not*
5386 ;; meant to be used as a whole unless it corresponds to your needs.
5387 ;; (In fact, this is a copy of Jack's setup for ps-print --
5388 ;; I would not be that surprised if it was useful to *anybody*,
5389 ;; without modification.)
5391 (defun ps-jack-setup ()
5392 (setq ps-print-color-p nil
5393 ps-lpr-command "lpr"
5398 ps-number-of-columns 2
5400 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5401 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5402 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
5403 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5404 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5405 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
5406 ps-header-line-pad .15
5408 ps-print-header-frame t
5413 ps-font-family 'Courier
5415 ps-header-font-family 'Helvetica
5416 ps-header-font-size 6
5417 ps-header-title-font-size 8)
5421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5422 ;; To make this file smaller, some commands go in a separate file.
5423 ;; But autoload them here to make the separation invisible.
5425 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
5426 "Setup special ASCII font for STRING.
5427 STRING should contain only ASCII characters.")
5429 (autoload 'ps-mule-set-ascii-font "ps-mule"
5430 "Adjust current font if current charset is not ASCII.")
5432 (autoload 'ps-mule-plot-string "ps-mule"
5433 "Generate PostScript code for ploting characters in the region FROM and TO.
5435 It is assumed that all characters in this region belong to the same charset.
5437 Optional argument BG-COLOR specifies background color.
5441 (ENDPOS . RUN-WIDTH)
5443 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
5446 (autoload 'ps-mule-initialize "ps-mule"
5447 "Initialize global data for printing multi-byte characters.")
5449 (autoload 'ps-mule-begin-job "ps-mule"
5450 "Start printing job for multi-byte chars between FROM and TO.
5451 This checks if all multi-byte characters in the region are printable or not.")
5453 (autoload 'ps-mule-begin-page "ps-mule"
5454 "Initialize multi-byte charset for printing current page.")
5457 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5461 ;;; ps-print.el ends here