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/03/29 15:45:24 vinicius>
15 (defconst ps-print-version
"5.1.3"
16 "ps-print.el, v 5.1.3 <2000/03/29 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,
20 please also report the version of Emacs, if any, that ps-print was
23 Please send all bug fixes and enhancements to
24 Vinicius Jose Latorre <vinicius@cpqd.com.br>.
27 ;; This file is part of GNU Emacs.
29 ;; GNU Emacs is free software; you can redistribute it and/or modify
30 ;; it under the terms of the GNU General Public License as published by
31 ;; the Free Software Foundation; either version 2, or (at your option)
34 ;; GNU Emacs is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 ;; GNU General Public License for more details.
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with GNU Emacs; see the file COPYING. If not, write to the
41 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
42 ;; Boston, MA 02111-1307, USA.
46 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 ;; This package provides printing of Emacs buffers on PostScript printers;
52 ;; the buffer's bold and italic text attributes are preserved in the printer
53 ;; output. ps-print is intended for use with Emacs or Lucid Emacs, together
54 ;; with a fontifying package such as font-lock or hilit.
56 ;; ps-print uses the same face attributes defined through font-lock or hilit
57 ;; to print a PostScript file, but some faces are better seeing on the screen
58 ;; than on paper, specially when you have a black/white PostScript printer.
60 ;; ps-print allows a remap of face to another one that it is better to print,
61 ;; for example, the face font-lock-comment-face (if you are using font-lock)
62 ;; could have bold or italic attribute when printing, besides foreground color.
63 ;; This remap improves printing look (see How Ps-Print Maps Faces).
69 ;; ps-print provides eight commands for generating PostScript images
73 ;; ps-print-buffer-with-faces
75 ;; ps-print-region-with-faces
77 ;; ps-spool-buffer-with-faces
79 ;; ps-spool-region-with-faces
81 ;; These commands all perform essentially the same function: they
82 ;; generate PostScript images suitable for printing on a PostScript
83 ;; printer or displaying with GhostScript. These commands are
84 ;; collectively referred to as "ps-print- commands".
86 ;; The word "print" or "spool" in the command name determines when the
87 ;; PostScript image is sent to the printer:
89 ;; print - The PostScript image is immediately sent to the
92 ;; spool - The PostScript image is saved temporarily in an
93 ;; Emacs buffer. Many images may be spooled locally
94 ;; before printing them. To send the spooled images
95 ;; to the printer, use the command `ps-despool'.
97 ;; The spooling mechanism was designed for printing lots of small
98 ;; files (mail messages or netnews articles) to save paper that would
99 ;; otherwise be wasted on banner pages, and to make it easier to find
100 ;; your output at the printer (it's easier to pick up one 50-page
101 ;; printout than to find 50 single-page printouts).
103 ;; ps-print has a hook in the `kill-emacs-hook' so that you won't
104 ;; accidentally quit from Emacs while you have unprinted PostScript
105 ;; waiting in the spool buffer. If you do attempt to exit with
106 ;; spooled PostScript, you'll be asked if you want to print it, and if
107 ;; you decline, you'll be asked to confirm the exit; this is modeled
108 ;; on the confirmation that Emacs uses for modified buffers.
110 ;; The word "buffer" or "region" in the command name determines how
111 ;; much of the buffer is printed:
113 ;; buffer - Print the entire buffer.
115 ;; region - Print just the current region.
117 ;; The -with-faces suffix on the command name means that the command
118 ;; will include font, color, and underline information in the
119 ;; PostScript image, so the printed image can look as pretty as the
120 ;; buffer. The ps-print- commands without the -with-faces suffix
121 ;; don't include font, color, or underline information; images printed
122 ;; with these commands aren't as pretty, but are faster to generate.
124 ;; Two ps-print- command examples:
126 ;; ps-print-buffer - print the entire buffer,
127 ;; without font, color, or
128 ;; underline information, and
129 ;; send it immediately to the
132 ;; ps-spool-region-with-faces - print just the current region;
133 ;; include font, color, and
134 ;; underline information, and
135 ;; spool the image in Emacs to
136 ;; send to the printer later.
142 ;; To print your buffer, type
144 ;; M-x ps-print-buffer
146 ;; or substitute one of the other seven ps-print- commands. The
147 ;; command will generate the PostScript image and print or spool it as
148 ;; specified. By giving the command a prefix argument
150 ;; C-u M-x ps-print-buffer
152 ;; it will save the PostScript image to a file instead of sending it
153 ;; to the printer; you will be prompted for the name of the file to
154 ;; save the image to. The prefix argument is ignored by the commands
155 ;; that spool their images, but you may save the spooled images to a
156 ;; file by giving a prefix argument to `ps-despool':
158 ;; C-u M-x ps-despool
160 ;; When invoked this way, `ps-despool' will prompt you for the name of
161 ;; the file to save to.
163 ;; Any of the `ps-print-' commands can be bound to keys; I recommend
164 ;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
165 ;; and `ps-despool'. Here are the bindings I use on my Sun 4 keyboard:
167 ;; (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
168 ;; (global-set-key '(shift f22) 'ps-spool-region-with-faces)
169 ;; (global-set-key '(control f22) 'ps-despool)
172 ;; The Printer Interface
173 ;; ---------------------
175 ;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
176 ;; command is used to send the PostScript images to the printer, and
177 ;; what arguments to give the command. These are analogous to
178 ;; `lpr-command' and `lpr-switches'.
180 ;; Make sure that they contain appropriate values for your system;
181 ;; see the usage notes below and the documentation of these variables.
183 ;; The variable `ps-printer-name' determines the name of a local printer for
184 ;; printing PostScript files.
186 ;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
187 ;; from the variables `lpr-command' and `lpr-switches'. If you have
188 ;; `lpr-command' set to invoke a pretty-printer such as `enscript',
189 ;; then ps-print won't work properly. `ps-lpr-command' must name
190 ;; a program that does not format the files it prints.
191 ;; `ps-printer-name' takes its initial value from the variable
194 ;; The variable `ps-print-region-function' specifies a function to print the
195 ;; region on a PostScript printer.
196 ;; See definition of `call-process-region' for calling conventions. The fourth
197 ;; and the sixth arguments are both nil.
203 ;; All dimensions are floats in PostScript points.
204 ;; 1 inch == 2.54 cm == 72 points
205 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
207 ;; The variable `ps-paper-type' determines the size of paper ps-print
208 ;; formats for; it should contain one of the symbols:
209 ;; `a4' `a3' `letter' `legal' `letter-small' `tabloid'
210 ;; `ledger' `statement' `executive' `a4small' `b4' `b5'
212 ;; The variable `ps-landscape-mode' determines the orientation
213 ;; of the printing on the page:
214 ;; nil means `portrait' mode, non-nil means `landscape' mode.
215 ;; There is no oblique mode yet, though this is easy to do in ps.
217 ;; In landscape mode, the text is NOT scaled: you may print 70 lines
218 ;; in portrait mode and only 50 lignes in landscape mode.
219 ;; The margins represent margins in the printed paper:
220 ;; the top margin is the margin between the top of the page
221 ;; and the printed header, whatever the orientation is.
223 ;; The variable `ps-number-of-columns' determines the number of columns
224 ;; both in landscape and portrait mode.
226 ;; - (the standard) one column portrait mode
227 ;; - (my favorite) two columns landscape mode (which spares trees)
229 ;; - one column landscape mode for files with very long lines.
230 ;; - multi-column portrait or landscape mode
236 ;; The horizontal layout is determined by the variables
237 ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
240 ;; ------------------------------------------
242 ;; | lm | text | ic | text | ic | text | rm |
244 ;; ------------------------------------------
246 ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
247 ;; Usually, lm = rm > 0 and ic = lm
248 ;; If (ic < 0), the text of adjacent columns can overlap.
254 ;; The vertical layout is determined by the variables
255 ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
258 ;; |--------| |--------|
260 ;; |--------| |--------|
264 ;; |--------| or | text |
268 ;; |--------| |--------|
270 ;; |--------| |--------|
272 ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
273 ;; The margins represent margins in the printed paper:
274 ;; the top margin is the margin between the top of the page
275 ;; and the printed header, whatever the orientation is.
281 ;; ps-print can print headers at the top of each column or at the top
282 ;; of each page; the default headers contain the following four items:
283 ;; on the left, the name of the buffer and, if the buffer is visiting
284 ;; a file, the file's directory; on the right, the page number and
285 ;; date of printing. The default headers look something like this:
288 ;; /home/jct/emacs-lisp/ps/new 94/12/31
290 ;; When printing on duplex printers, left and right are reversed so
291 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
293 ;; Headers are configurable:
294 ;; To turn them off completely, set `ps-print-header' to nil.
295 ;; To turn off the header's gaudy framing box,
296 ;; set `ps-print-header-frame' to nil.
298 ;; To print only one header at the top of each page,
299 ;; set `ps-print-only-one-header' to t.
301 ;; The font family and size of text in the header are determined
302 ;; by the variables `ps-header-font-family', `ps-header-font-size' and
303 ;; `ps-header-title-font-size' (see below).
305 ;; The variable `ps-header-line-pad' determines the portion of a header
306 ;; title line height to insert between the header frame and the text
307 ;; it contains, both in the vertical and horizontal directions:
308 ;; .5 means half a line.
310 ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
311 ;; to omit the total page count and just print the page number,
312 ;; set `ps-show-n-of-n' to nil.
314 ;; The amount of information in the header can be changed by changing
315 ;; the number of lines. To show less, set `ps-header-lines' to 1, and
316 ;; the header will show only the buffer name and page number. To show
317 ;; more, set `ps-header-lines' to 3, and the header will show the time of
318 ;; printing below the date.
320 ;; To change the content of the headers, change the variables
321 ;; `ps-left-header' and `ps-right-header'.
322 ;; These variables are lists, specifying top-to-bottom the text
323 ;; to display on the left or right side of the header.
324 ;; Each element of the list should be a string or a symbol.
325 ;; Strings are inserted directly into the PostScript arrays,
326 ;; and should contain the PostScript string delimiters '(' and ')'.
328 ;; Symbols in the header format lists can either represent functions
329 ;; or variables. Functions are called, and should return a string to
330 ;; show in the header. Variables should contain strings to display in
331 ;; the header. In either case, function or variable, the PostScript
332 ;; string delimiters are added by ps-print, and should not be part of
333 ;; the returned value.
335 ;; Here's an example: say we want the left header to display the text
341 ;; where we have a function to return "Moe"
343 ;; (defun moe-func ()
346 ;; a variable specifying "Larry"
348 ;; (setq larry-var "Larry")
350 ;; and a literal for "Curly". Here's how `ps-left-header' should be
353 ;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
355 ;; Note that Curly has the PostScript string delimiters inside his
356 ;; quotes -- those aren't misplaced lisp delimiters!
358 ;; Without them, PostScript would attempt to call the undefined
359 ;; function Curly, which would result in a PostScript error.
361 ;; Since most printers don't report PostScript errors except by
362 ;; aborting the print job, this kind of error can be hard to track down.
364 ;; Consider yourself warned!
367 ;; PostScript Prologue Header
368 ;; --------------------------
370 ;; It is possible to add PostScript prologue header comments besides that
371 ;; ps-print generates by setting the variable `ps-print-prologue-header'.
373 ;; `ps-print-prologue-header' may be a string or a symbol function which returns
374 ;; a string. Note that this string is inserted on PostScript prologue header
375 ;; section which is used to define some document characteristic through
376 ;; PostScript special comments, like "%%Requirements: jog\n".
378 ;; By default `ps-print-prologue-header' is nil.
380 ;; ps-print always inserts the %%Requirements: comment, so if you need to insert
381 ;; more requirements put them first in `ps-print-prologue-header' using the
382 ;; "%%+" comment. For example, if you need to set numcopies to 3 and jog on
383 ;; requirements and set %%LanguageLevel: to 2, do:
385 ;; (setq ps-print-prologue-header
386 ;; "%%+ numcopies(3) jog\n%%LanguageLevel: 2\n")
388 ;; The duplex requirement is inserted by ps-print (see section Duplex Printers).
390 ;; Do not forget to terminate the string with "\n".
392 ;; For more information about PostScript document comments, see:
393 ;; PostScript Language Reference Manual (2nd edition)
394 ;; Adobe Systems Incorporated
395 ;; Appendix G: Document Structuring Conventions -- Version 3.0
397 ;; It is also possible to add an user defined PostScript prologue code before
398 ;; all generated prologue code by setting the variable
399 ;; `ps-user-defined-prologue'.
401 ;; `ps-user-defined-prologue' may be a string or a symbol function which returns
402 ;; a string. Note that this string is inserted after `ps-adobe-tag' and
403 ;; PostScript prologue comments, and before ps-print PostScript prologue code
404 ;; section. That is, this string is inserted after error handler initialization
405 ;; and before ps-print settings.
407 ;; By default `ps-user-defined-prologue' is nil.
409 ;; It's recommended to initiate and terminate the string with "\n".
411 ;; It's strongly recommended only insert PostScript code and/or comments
412 ;; specific for your printing system particularities. For example, some special
413 ;; initialization that only your printing system needs.
415 ;; Do not insert code for duplex printing, n-up printing or error handler,
416 ;; ps-print handles this in a suitable way.
418 ;; For more information about PostScript, see:
419 ;; PostScript Language Reference Manual (2nd edition)
420 ;; Adobe Systems Incorporated
423 ;; PostScript Error Handler
424 ;; ------------------------
426 ;; ps-print instruments generated PostScript code with an error handler.
428 ;; The variable `ps-error-handler-message' specifies where the error handler
429 ;; message should be sent.
433 ;; none catch the error and *DON'T* send any message.
435 ;; paper catch the error and print on paper the error message.
436 ;; This is the default value.
438 ;; system catch the error and send back the error message to
439 ;; printing system. This is useful only if printing system
440 ;; send back an email reporting the error, or if there is
441 ;; some other alternative way to report back the error from
442 ;; the system to you.
444 ;; paper-and-system catch the error, print on paper the error message and
445 ;; send back the error message to printing system.
447 ;; Any other value is treated as `paper'.
453 ;; If you have a duplex-capable printer (one that prints both sides of the
454 ;; paper), set `ps-spool-duplex' to t.
455 ;; ps-print will insert blank pages to make sure each buffer starts on the
456 ;; correct side of the paper.
458 ;; The variable `ps-spool-config' specifies who is the responsable for setting
459 ;; duplex and page size switches. Valid values are:
461 ;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
462 ;; Don't forget to set `ps-lpr-switches' to select duplex
463 ;; printing for your printer.
465 ;; setpagedevice duplex and page size are configured by ps-print using the
466 ;; setpagedevice PostScript operator.
468 ;; nil duplex and page size are configured by ps-print *not* using
469 ;; the setpagedevice PostScript operator.
471 ;; Any other value is treated as nil.
473 ;; The default value is `lpr-switches'.
475 ;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
476 ;; viewing file generated using landscape. Also on some printers,
477 ;; setpagedevice affects zebra stripes; on other printers,
478 ;; setpagedevice affects the left margin.
479 ;; Besides all that, if your printer does not have the paper size
480 ;; specified by setpagedevice, your printing will be aborted.
481 ;; So, if you need to use setpagedevice, set `ps-spool-config' to
482 ;; `setpagedevice', generate a test file and send it to your printer;
483 ;; if the printed file isn't ok, set `ps-spool-config' to nil.
485 ;; The variable `ps-spool-tumble' specifies how the page images on opposite
486 ;; sides of a sheet are oriented with respect to each other. If
487 ;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
488 ;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
489 ;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
490 ;; The default value is nil.
492 ;; Some printer system prints a header page and forces the first page be printed
493 ;; on header page back, when using duplex. If your printer system has this
494 ;; behavior, set variable `ps-banner-page-when-duplexing' to t.
496 ;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
497 ;; skipped. It's like the very first character of buffer (or region) is ^L
500 ;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
507 ;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
508 ;; paper. The value specified must be between 1 and 100. The default is 1.
510 ;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
511 ;; to a high value (for example, 23). If this happens, set a lower value.
513 ;; The variable `ps-n-up-margin' specifies the margin in points between the
514 ;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
517 ;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
520 ;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
521 ;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
522 ;; filling example using a 3x4 page matrix:
524 ;; left-top 1 2 3 4 left-bottom 9 10 11 12
526 ;; 9 10 11 12 1 2 3 4
528 ;; right-top 4 3 2 1 right-bottom 12 11 10 9
530 ;; 12 11 10 9 4 3 2 1
532 ;; top-left 1 4 7 10 bottom-left 3 6 9 12
536 ;; top-right 10 7 4 1 bottom-right 12 9 6 3
540 ;; Any other value is treated as left-top.
542 ;; The default value is left-top.
545 ;; Control And 8-bit Characters
546 ;; ----------------------------
548 ;; The variable `ps-print-control-characters' specifies whether you want to see
549 ;; a printable form for control and 8-bit characters, that is, instead of
550 ;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
552 ;; Valid values for `ps-print-control-characters' are:
554 ;; 8-bit This is the value to use when you want an ASCII encoding of
555 ;; any control or non-ASCII character. Control characters are
556 ;; encoded as "^D", and non-ASCII characters have an
559 ;; control-8-bit This is the value to use when you want an ASCII encoding of
560 ;; any control character, whether it is 7 or 8-bit.
561 ;; European 8-bits accented characters are printed according
564 ;; control Only ASCII control characters have an ASCII encoding.
565 ;; European 8-bits accented characters are printed according
568 ;; nil No ASCII encoding. Any character is printed according the
571 ;; Any other value is treated as nil.
573 ;; The default is `control-8-bit'.
575 ;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
578 ;; Printing Multi-byte Buffer
579 ;; --------------------------
581 ;; See ps-mule.el for documentation.
587 ;; The variable `ps-line-number' specifies whether to number each line;
588 ;; non-nil means do so. The default is nil (don't number each line).
594 ;; Zebra stripes are a kind of background that appear "underneath" the text
595 ;; and can make the text easier to read. They look like this:
597 ;; XXXXXXXXXXXXXXXXXXXXXXXX
598 ;; XXXXXXXXXXXXXXXXXXXXXXXX
599 ;; XXXXXXXXXXXXXXXXXXXXXXXX
603 ;; XXXXXXXXXXXXXXXXXXXXXXXX
604 ;; XXXXXXXXXXXXXXXXXXXXXXXX
605 ;; XXXXXXXXXXXXXXXXXXXXXXXX
607 ;; The blocks of X's represent rectangles filled with a light gray color.
608 ;; Each rectangle extends all the way across the page.
610 ;; The height, in lines, of each rectangle is controlled by
611 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
612 ;; The distance between stripes equals the height of a stripe.
614 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
615 ;; Non-nil means yes, nil means no. The default is nil.
617 ;; The variable `ps-zebra-color' controls the zebra stripes gray scale or RGB
618 ;; color. It should be a float number between 0.0 (black color) and 1.0 (white
619 ;; color), a string which is a color name, or a list of 3 numbers which
620 ;; corresponds to the Red Green Blue color scale.
621 ;; The default is 0.95 (or "gray95", or '(0.95 0.95 0.95)).
623 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
629 ;; ps-print has the following hook variables:
632 ;; It is evaluated once before any printing process. This is the right
633 ;; place to initialize ps-print global data.
634 ;; For an example, see section Adding a New Font Family.
636 ;; `ps-print-begin-sheet-hook'
637 ;; It is evaluated on each beginning of sheet of paper.
638 ;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
641 ;; `ps-print-begin-page-hook'
642 ;; It is evaluated on each beginning of page, except in the beginning
643 ;; of page that `ps-print-begin-sheet-hook' is evaluated.
645 ;; `ps-print-begin-column-hook'
646 ;; It is evaluated on each beginning of column, except in the beginning
647 ;; of column that `ps-print-begin-page-hook' is evaluated or that
648 ;; `ps-print-begin-sheet-hook' is evaluated.
654 ;; ps-print now knows rather precisely some fonts: the variable
655 ;; `ps-font-info-database' contains information for a list of font families
656 ;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
657 ;; `NewCenturySchlbk'). Each font family contains the font names for standard,
658 ;; bold, italic and bold-italic characters, a reference size (usually 10) and
659 ;; the corresponding line height, width of a space and average character width.
661 ;; The variable `ps-font-family' determines which font family is to be used for
662 ;; ordinary text. If its value does not correspond to a known font family, an
663 ;; error message is printed into the `*Messages*' buffer, which lists the
664 ;; currently available font families.
666 ;; The variable `ps-font-size' determines the size (in points) of the font for
667 ;; ordinary text, when generating PostScript. Its value is a float or a cons of
668 ;; floats which has the following form:
670 ;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
672 ;; Similarly, the variable `ps-header-font-family' determines which font family
673 ;; is to be used for text in the header.
675 ;; The variable `ps-header-font-size' determines the font size, in points, for
676 ;; text in the header (similar to `ps-font-size').
678 ;; The variable `ps-header-title-font-size' determines the font size, in points,
679 ;; for the top line of text in the header (similar to `ps-font-size').
682 ;; Adding a New Font Family
683 ;; ------------------------
685 ;; To use a new font family, you MUST first teach ps-print
686 ;; this font, i.e., add its information to `ps-font-info-database',
687 ;; otherwise ps-print cannot correctly place line and page breaks.
689 ;; For example, assuming `Helvetica' is unknown,
690 ;; you first need to do the following ONLY ONCE:
692 ;; - create a new buffer
693 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
694 ;; - open this file and find the line:
695 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
696 ;; - delete the leading `%' (which is the PostScript comment character)
697 ;; - replace in this line `Courier' by the new font (say `Helvetica')
699 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
700 ;; - send this file to the printer (or to ghostscript).
701 ;; You should read the following on the output page:
703 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
704 ;; and a crude estimate of average character width is 5.09243
706 ;; - Add these values to the `ps-font-info-database':
707 ;; (setq ps-font-info-database
709 ;; '((Helvetica ; the family key
710 ;; (fonts (normal . "Helvetica")
711 ;; (bold . "Helvetica-Bold")
712 ;; (italic . "Helvetica-Oblique")
713 ;; (bold-italic . "Helvetica-BoldOblique"))
715 ;; (line-height . 11.56)
716 ;; (space-width . 2.78)
717 ;; (avg-char-width . 5.09243)))
718 ;; ps-font-info-database))
719 ;; - Now you can use this font family with any size:
720 ;; (setq ps-font-family 'Helvetica)
721 ;; - if you want to use this family in another emacs session, you must
722 ;; put into your `~/.emacs':
723 ;; (require 'ps-print)
724 ;; (setq ps-font-info-database (append ...)))
725 ;; if you don't want to load ps-print, you have to copy the whole value:
726 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
727 ;; or, use `ps-print-hook' (see section Hooks):
728 ;; (add-hook 'ps-print-hook
730 ;; (or (assq 'Helvetica ps-font-info-database)
731 ;; (setq ps-font-info-database (append ...)))))
733 ;; You can create new `mixed' font families like:
735 ;; (fonts (normal . "Courier-Bold")
736 ;; (bold . "Helvetica")
737 ;; (italic . "Zapf-Chancery-MediumItalic")
738 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
739 ;; (w3-table-hack-x-face . "LineDrawNormal"))
741 ;; (line-height . 10.55)
742 ;; (space-width . 6.0)
743 ;; (avg-char-width . 6.0))
745 ;; Now you can use your new font family with any size:
746 ;; (setq ps-font-family 'my-mixed-family)
748 ;; Note that on above example the `w3-table-hack-x-face' entry refers to
749 ;; a face symbol, so when printing this face it'll be used the font
750 ;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
751 ;; use bold and/or italic attribute, the corresponding entry (bold, italic
752 ;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
754 ;; Note also that the font family entry order is irrelevant, so the above
755 ;; example could also be written:
758 ;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
759 ;; (bold . "Helvetica")
760 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
761 ;; (italic . "Zapf-Chancery-MediumItalic")
762 ;; (normal . "Courier-Bold"))
763 ;; (avg-char-width . 6.0)
764 ;; (space-width . 6.0)
765 ;; (line-height . 10.55))
767 ;; Despite the note above, it is recommended that some convention about
768 ;; entry order be used.
770 ;; You can get information on all the fonts resident in YOUR printer
771 ;; by uncommenting the line:
772 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
774 ;; The PostScript file should be sent to YOUR PostScript printer.
775 ;; If you send it to ghostscript or to another PostScript printer,
776 ;; you may get slightly different results.
777 ;; Anyway, as ghostscript fonts are autoload, you won't get
781 ;; How Ps-Print Deals With Faces
782 ;; -----------------------------
784 ;; The ps-print-*-with-faces commands attempt to determine which faces
785 ;; should be printed in bold or italic, but their guesses aren't
786 ;; always right. For example, you might want to map colors into faces
787 ;; so that blue faces print in bold, and red faces in italic.
789 ;; It is possible to force ps-print to consider specific faces bold,
790 ;; italic or underline, no matter what font they are displayed in, by setting
791 ;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
792 ;; These variables contain lists of faces that ps-print should consider bold,
793 ;; italic or underline; to set them, put code like the following into your
796 ;; (setq ps-bold-faces '(my-blue-face))
797 ;; (setq ps-italic-faces '(my-red-face))
798 ;; (setq ps-underlined-faces '(my-green-face))
800 ;; Faces like bold-italic that are both bold and italic should go in
803 ;; ps-print keeps internal lists of which fonts are bold and which are
804 ;; italic; these lists are built the first time you invoke ps-print.
805 ;; For the sake of efficiency, the lists are built only once; the same
806 ;; lists are referred in later invocations of ps-print.
808 ;; Because these lists are built only once, it's possible for them to
809 ;; get out of sync, if a face changes, or if new faces are added. To
810 ;; get the lists back in sync, you can set the variable
811 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
812 ;; next time ps-print is invoked. If you need that the lists always be
813 ;; rebuilt when ps-print is invoked, set the variable
814 ;; `ps-always-build-face-reference' to t.
817 ;; How Ps-Print Deals With Color
818 ;; -----------------------------
820 ;; ps-print detects faces with foreground and background colors
821 ;; defined and embeds color information in the PostScript image.
822 ;; The default foreground and background colors are defined by the
823 ;; variables `ps-default-fg' and `ps-default-bg'.
824 ;; On black-and-white printers, colors are displayed in gray scale.
825 ;; To turn off color output, set `ps-print-color-p' to nil.
828 ;; How Ps-Print Maps Faces
829 ;; -----------------------
831 ;; As ps-print uses PostScript to print buffers, it is possible to have
832 ;; other attributes associated with faces. So the new attributes used
835 ;; strikeout - like underline, but the line is in middle of text.
836 ;; overline - like underline, but the line is over the text.
837 ;; shadow - text will have a shadow.
838 ;; box - text will be surrounded by a box.
839 ;; outline - print characters as hollow outlines.
841 ;; See the documentation for `ps-extend-face'.
843 ;; Let's, for example, remap `font-lock-keyword-face' to another foreground
844 ;; color and bold attribute:
846 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
848 ;; If you want to use a new face, define it first with `defface',
849 ;; and then call `ps-extend-face' to specify how to print it.
852 ;; How Ps-Print Has A Text And/Or Image On Background
853 ;; --------------------------------------------------
855 ;; ps-print can print texts and/or EPS PostScript images on background; it is
856 ;; possible to define the following text attributes: font name, font size,
857 ;; initial position, angle, gray scale and pages to print.
859 ;; It has the following EPS PostScript images attributes: file name containing
860 ;; the image, initial position, X and Y scales, angle and pages to print.
862 ;; See documentation for `ps-print-background-text' and
863 ;; `ps-print-background-image'.
865 ;; For example, if we wish to print text "preliminary" on all pages and text
866 ;; "special" on page 5 and from page 11 to page 17, we could specify:
868 ;; (setq ps-print-background-text
871 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
872 ;; ; (upper left corner)
874 ;; "PrintHeight neg PrintPageWidth atan" ; angle
875 ;; 5 (11 . 17)) ; page list
878 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
879 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
882 ;; (setq ps-print-background-image
883 ;; '(("~/images/EPS-image1.ps"
884 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
885 ;; ("~/images/EPS-image2.ps"
886 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
887 ;; ; (upper left corner)
889 ;; 5 (11 . 17)) ; page list
892 ;; If it is not possible to read (or does not exist) an image file, that file
895 ;; The printing order is:
897 ;; 1. Print background color
898 ;; 2. Print zebra stripes
899 ;; 3. Print background texts that it should be on all pages
900 ;; 4. Print background images that it should be on all pages
901 ;; 5. Print background texts only for current page (if any)
902 ;; 6. Print background images only for current page (if any)
904 ;; 8. Print buffer text (with faces, if specified) and line number
910 ;; Some tools are provided to help you customize your font setup.
912 ;; `ps-setup' returns (some part of) the current setup.
914 ;; To avoid wrapping too many lines, you may want to adjust the
915 ;; left and right margins and the font size. On UN*X systems, do:
916 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
917 ;; to determine the longest lines of your file.
918 ;; Then, the command `ps-line-lengths' will give you the correspondence
919 ;; between a line length (number of characters) and the maximum font
920 ;; size which doesn't wrap such a line with the current ps-print setup.
922 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
923 ;; the correspondence between a number of pages and the maximum font
924 ;; size which allow the number of lines of the current buffer or of
925 ;; its current region to fit in this number of pages.
927 ;; NOTE: line folding is not taken into account in this process and could
928 ;; change the results.
930 ;; The command `ps-print-customize' activates a customization buffer for
934 ;; New since version 1.5
935 ;; ---------------------
937 ;; Color output capability.
938 ;; Automatic detection of font attributes (bold, italic).
939 ;; Configurable headers with page numbers.
941 ;; Support for different paper sizes.
942 ;; Better conformance to PostScript Document Structure Conventions.
945 ;; New since version 2.8
946 ;; ---------------------
948 ;; [vinicius] 20000310 Vinicius Jose Latorre <vinicius@cpqd.com.br>
950 ;; PostScript error handler.
951 ;; `ps-user-defined-prologue' and `ps-error-handler-message'.
953 ;; [vinicius] 991211 Vinicius Jose Latorre <vinicius@cpqd.com.br>
955 ;; `ps-print-customize'.
957 ;; [vinicius] 990703 Vinicius Jose Latorre <vinicius@cpqd.com.br>
959 ;; Better customization.
960 ;; `ps-banner-page-when-duplexing' and `ps-zebra-color'.
962 ;; [vinicius] 990513 Vinicius Jose Latorre <vinicius@cpqd.com.br>
965 ;; Hook: `ps-print-begin-sheet-hook'.
967 ;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
969 ;; `ps-print-region-function'
971 ;; [vinicius] 990301 Vinicius Jose Latorre <vinicius@cpqd.com.br>
973 ;; PostScript tumble and setpagedevice.
975 ;; [vinicius] 980922 Vinicius Jose Latorre <vinicius@cpqd.com.br>
977 ;; PostScript prologue header comment insertion.
978 ;; Skip invisible text better.
980 ;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
982 ;; Multi-byte buffer handling.
984 ;; [vinicius] 980306 Vinicius Jose Latorre <vinicius@cpqd.com.br>
986 ;; Skip invisible text.
988 ;; [vinicius] 971130 Vinicius Jose Latorre <vinicius@cpqd.com.br>
990 ;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
991 ;; `ps-print-begin-column-hook'.
992 ;; Put one header per page over the columns.
993 ;; Better database font management.
994 ;; Better control characters handling.
996 ;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
998 ;; Dynamic evaluation at print time of `ps-lpr-switches'.
999 ;; Handle control characters.
1001 ;; New face attributes.
1004 ;; Text and/or image on background.
1006 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
1008 ;; Font family and float size for text and header.
1010 ;; Multiple columns.
1011 ;; Tools for page setup.
1014 ;; Known bugs and limitations of ps-print
1015 ;; --------------------------------------
1017 ;; Although color printing will work in XEmacs 19.12, it doesn't work
1018 ;; well; in particular, bold or italic fonts don't print in the right
1019 ;; background color.
1021 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
1023 ;; Automatic font-attribute detection doesn't work well, especially
1024 ;; with hilit19 and older versions of get-create-face. Users having
1025 ;; problems with auto-font detection should use the lists
1026 ;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
1027 ;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
1029 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
1030 ;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
1031 ;; `ps-underlined-faces' instead.
1033 ;; Still too slow; could use some hand-optimization.
1035 ;; Default background color isn't working.
1037 ;; Faces are always treated as opaque.
1039 ;; Epoch and Emacs 19 not supported. At all.
1041 ;; Fixed-pitch fonts work better for line folding, but are not required.
1043 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
1044 ;; of folding lines.
1050 ;; Avoid page break inside a paragraph.
1051 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
1052 ;; Improve the memory management for big files (hard?).
1053 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1054 ;; of folding lines.
1060 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for user defined PostScript
1061 ;; prologue code suggestion.
1063 ;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
1065 ;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1068 ;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1071 ;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1072 ;; `ps-print-control-characters' variable documentation.
1074 ;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1075 ;; database font management.
1077 ;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
1078 ;; header per page over the columns and correct line numbers when printing a
1081 ;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1082 ;; print time of `ps-lpr-switches'.
1084 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1085 ;; (his code was severely modified, but the main idea was kept).
1087 ;; Thanks to some suggestions on:
1088 ;; * Face color map: Marco Melgazzi <marco@techie.com>
1089 ;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
1090 ;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
1092 ;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1093 ;; I started from. [vinicius]
1095 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1098 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1099 ;; color and the invisible property.
1101 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1102 ;; the initial port to Emacs 19. His code is no longer part of
1103 ;; ps-print, but his work is still appreciated.
1105 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1106 ;; for adding underline support. Their code also is no longer part of
1107 ;; ps-print, but their efforts are not forgotten.
1109 ;; Thanks also to all of you who mailed code to add features to
1110 ;; ps-print; although I didn't use your code, I still appreciate your
1111 ;; sharing it with me.
1113 ;; Thanks to all who mailed comments, encouragement, and criticism.
1114 ;; Thanks also to all who responded to my survey; I had too many
1115 ;; responses to reply to them all, but I greatly appreciate your
1119 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1123 (unless (featurep 'lisp-float-type
)
1124 (error "`ps-print' requires floating point support"))
1127 ;; For Emacs 20.2 and the earlier version.
1129 (or (fboundp 'set-buffer-multibyte
)
1130 (defun set-buffer-multibyte (arg)
1131 (setq enable-multibyte-characters arg
)))
1133 (or (fboundp 'string-as-unibyte
)
1134 (defun string-as-unibyte (arg) arg
))
1136 (or (fboundp 'string-as-multibyte
)
1137 (defun string-as-multibyte (arg) arg
))
1139 (or (fboundp 'charset-after
)
1140 (defun charset-after (&optional arg
)
1141 (char-charset (char-after arg
))))
1144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1148 ;;; Interface to the command system
1150 (defgroup postscript nil
1155 (defgroup ps-print nil
1156 "PostScript generator for Emacs 19"
1161 (defgroup ps-print-horizontal nil
1162 "Horizontal page layout"
1167 (defgroup ps-print-vertical nil
1168 "Vertical page layout"
1173 (defgroup ps-print-headers nil
1179 (defgroup ps-print-font nil
1180 "Fonts customization"
1185 (defgroup ps-print-color nil
1186 "Color customization"
1191 (defgroup ps-print-face nil
1192 "Faces customization"
1198 (defgroup ps-print-n-up nil
1199 "N-up customization"
1204 (defgroup ps-print-zebra nil
1205 "Zebra customization"
1210 (defgroup ps-print-background nil
1211 "Background customization"
1216 (defgroup ps-print-printer nil
1217 "Printer customization"
1222 (defgroup ps-print-page nil
1223 "Page customization"
1228 (defgroup ps-print-miscellany nil
1229 "Miscellany customization"
1235 (defcustom ps-error-handler-message
'paper
1236 "*Specify where the error handler message should be sent.
1240 `none' catch the error and *DON'T* send any message.
1242 `paper' catch the error and print on paper the error message.
1244 `system' catch the error and send back the error message to
1245 printing system. This is useful only if printing system
1246 send back an email reporting the error, or if there is
1247 some other alternative way to report back the error from
1250 `paper-and-system' catch the error, print on paper the error message and
1251 send back the error message to printing system.
1253 Any other value is treated as `paper'."
1254 :type
'(choice :tag
"Error Handler Message"
1255 (const none
) (const paper
)
1256 (const system
) (const paper-and-system
))
1257 :group
'ps-print-miscellany
)
1259 (defcustom ps-user-defined-prologue nil
1260 "*User defined PostScript prologue code inserted before all prologue code.
1262 `ps-user-defined-prologue' may be a string or a symbol function which returns a
1263 string. Note that this string is inserted after `ps-adobe-tag' and PostScript
1264 prologue comments, and before ps-print PostScript prologue code section. That
1265 is, this string is inserted after error handler initialization and before
1268 It's recommended to initiate and terminate the string with \"\\n\".
1270 It's strongly recommended only insert PostScript code and/or comments specific
1271 for your printing system particularities. For example, some special
1272 initialization that only your printing system needs.
1274 Do not insert code for duplex printing, n-up printing or error handler, ps-print
1275 handles this in a suitable way.
1277 For more information about PostScript, see:
1278 PostScript Language Reference Manual (2nd edition)
1279 Adobe Systems Incorporated"
1280 :type
'(choice :tag
"User Defined Prologue"
1281 string symbol
(other :tag
"nil" nil
))
1282 :group
'ps-print-miscellany
)
1284 (defcustom ps-print-prologue-header nil
1285 "*PostScript prologue header comments besides that ps-print generates.
1287 `ps-print-prologue-header' may be a string or a symbol function which
1288 returns a string. Note that this string is inserted on PostScript prologue
1289 header section which is used to define some document characteristic through
1290 PostScript special comments, like \"%%Requirements: jog\\n\".
1292 ps-print always inserts the %%Requirements: comment, so if you need to insert
1293 more requirements put them first in `ps-print-prologue-header' using the
1294 \"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1295 requirements and set %%LanguageLevel: to 2, do:
1297 (setq ps-print-prologue-header
1298 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1300 The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1302 Do not forget to terminate the string with \"\\n\".
1304 For more information about PostScript document comments, see:
1305 PostScript Language Reference Manual (2nd edition)
1306 Adobe Systems Incorporated
1307 Appendix G: Document Structuring Conventions -- Version 3.0"
1308 :type
'(choice :tag
"Prologue Header"
1309 string symbol
(other :tag
"nil" nil
))
1310 :group
'ps-print-miscellany
)
1312 (defcustom ps-printer-name
(and (boundp 'printer-name
)
1314 "*The name of a local printer for printing PostScript files.
1316 On Unix-like systems, a string value should be a name understood by
1317 lpr's -P option; a value of nil means use the value of `printer-name'
1318 instead. Any other value will be ignored.
1320 On MS-DOS and MS-Windows systems, a string value is taken as the name of
1321 the printer device or port to which PostScript files are written,
1322 provided `ps-lpr-command' is \"\". By default it is the same as
1323 `printer-name'; typical non-default settings would be \"LPT1\" to
1324 \"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1325 serial printers, or \"//hostname/printer\" for a shared network printer.
1326 You can also set it to a name of a file, in which case the output gets
1327 appended to that file. \(Note that `ps-print' package already has
1328 facilities for printing to a file, so you might as well use them instead
1329 of changing the setting of this variable.\) If you want to silently
1330 discard the printed output, set this to \"NUL\"."
1331 :type
'(choice :tag
"Printer Name"
1332 (file :tag
"Print to file")
1333 (string :tag
"Pipe to ps-lpr-command")
1334 (other :tag
"Same as printer-name" nil
))
1335 :group
'ps-print-printer
)
1337 (defcustom ps-lpr-command lpr-command
1338 "*Name of program for printing a PostScript file.
1340 On MS-DOS and MS-Windows systems, if the value is an empty string then
1341 Emacs will write directly to the printer port named by `ps-printer-name'.
1342 The programs `print' and `nprint' (the standard print programs on Windows
1343 NT and Novell Netware respectively) are handled specially, using
1344 `ps-printer-name' as the destination for output; any other program is
1345 treated like `lpr' except that an explicit filename is given as the last
1348 :group
'ps-print-printer
)
1350 (defcustom ps-lpr-switches lpr-switches
1351 "*A list of extra switches to pass to `ps-lpr-command'."
1352 :type
'(repeat string
)
1353 :group
'ps-print-printer
)
1355 (defcustom ps-print-region-function nil
1356 "*Specify a function to print the region on a PostScript printer.
1357 See definition of `call-process-region' for calling conventions. The fourth and
1358 the sixth arguments are both nil."
1360 :group
'ps-print-printer
)
1364 ;; All page dimensions are in PostScript points.
1365 ;; 1 inch == 2.54 cm == 72 points
1366 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1368 ;; Letter 8.5 inch x 11.0 inch
1369 ;; Legal 8.5 inch x 14.0 inch
1370 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1372 ;; LetterSmall 7.68 inch x 10.16 inch
1373 ;; Tabloid 11.0 inch x 17.0 inch
1374 ;; Ledger 17.0 inch x 11.0 inch
1375 ;; Statement 5.5 inch x 8.5 inch
1376 ;; Executive 7.5 inch x 10.0 inch
1377 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1378 ;; A4Small 7.47 inch x 10.85 inch
1379 ;; B4 10.125 inch x 14.33 inch
1380 ;; B5 7.16 inch x 10.125 inch
1382 (defcustom ps-page-dimensions-database
1383 (list (list 'a4
(/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1384 (list 'a3
(/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1385 (list 'letter
(* 72 8.5) (* 72 11.0) "Letter")
1386 (list 'legal
(* 72 8.5) (* 72 14.0) "Legal")
1387 (list 'letter-small
(* 72 7.68) (* 72 10.16) "LetterSmall")
1388 (list 'tabloid
(* 72 11.0) (* 72 17.0) "Tabloid")
1389 (list 'ledger
(* 72 17.0) (* 72 11.0) "Ledger")
1390 (list 'statement
(* 72 5.5) (* 72 8.5) "Statement")
1391 (list 'executive
(* 72 7.5) (* 72 10.0) "Executive")
1392 (list 'a4small
(* 72 7.47) (* 72 10.85) "A4Small")
1393 (list 'b4
(* 72 10.125) (* 72 14.33) "B4")
1394 (list 'b5
(* 72 7.16) (* 72 10.125) "B5"))
1395 "*List associating a symbolic paper type to its width, height and doc media.
1396 See `ps-paper-type'."
1397 :type
'(repeat (list :tag
"Paper Type"
1398 (symbol :tag
"Name")
1399 (number :tag
"Width")
1400 (number :tag
"Height")
1401 (string :tag
"Media")))
1402 :group
'ps-print-page
)
1405 (defcustom ps-paper-type
'letter
1406 "*Specify the size of paper to format for.
1407 Should be one of the paper types defined in `ps-page-dimensions-database', for
1408 example `letter', `legal' or `a4'."
1409 :type
'(symbol :validate
(lambda (wid)
1410 (if (assq (widget-value wid
)
1411 ps-page-dimensions-database
)
1413 (widget-put wid
:error
"Unknown paper size")
1415 :group
'ps-print-page
)
1417 (defcustom ps-landscape-mode nil
1418 "*Non-nil means print in landscape mode."
1420 :group
'ps-print-page
)
1422 (defcustom ps-print-control-characters
'control-8-bit
1423 "*Specify the printable form for control and 8-bit characters.
1424 That is, instead of sending, for example, a ^D (\\004) to printer,
1425 it is sent the string \"^D\".
1429 `8-bit' This is the value to use when you want an ASCII encoding of
1430 any control or non-ASCII character. Control characters are
1431 encoded as \"^D\", and non-ASCII characters have an
1434 `control-8-bit' This is the value to use when you want an ASCII encoding of
1435 any control character, whether it is 7 or 8-bit.
1436 European 8-bits accented characters are printed according
1439 `control' Only ASCII control characters have an ASCII encoding.
1440 European 8-bits accented characters are printed according
1443 nil No ASCII encoding. Any character is printed according the
1446 Any other value is treated as nil."
1447 :type
'(choice :tag
"Control Char"
1448 (const 8-bit
) (const control-8-bit
)
1449 (const control
) (other :tag
"nil" nil
))
1450 :group
'ps-print-miscellany
)
1452 (defcustom ps-n-up-printing
1
1453 "*Specify the number of pages per sheet paper."
1455 :tag
"N Up Printing"
1458 (if (and (< 0 (widget-value wid
))
1459 (<= (widget-value wid
) 100))
1463 "Number of pages per sheet paper must be between 1 and 100.")
1465 :group
'ps-print-n-up
)
1467 (defcustom ps-n-up-margin
(/ (* 72 1.0) 2.54) ; 1 cm
1468 "*Specify the margin in points between the sheet border and n-up printing."
1470 :group
'ps-print-n-up
)
1472 (defcustom ps-n-up-border-p t
1473 "*Non-nil means a border is drawn around each page."
1475 :group
'ps-print-n-up
)
1477 (defcustom ps-n-up-filling
'left-top
1478 "*Specify how page matrix is filled on each sheet of paper.
1480 Following are the valid values for `ps-n-up-filling' with a filling example
1481 using a 3x4 page matrix:
1483 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1487 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1491 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1495 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1499 Any other value is treated as `left-top'."
1500 :type
'(choice :tag
"N-Up Filling"
1501 (const left-top
) (const left-bottom
)
1502 (const right-top
) (const right-bottom
)
1503 (const top-left
) (const bottom-left
)
1504 (const top-right
) (const bottom-right
))
1505 :group
'ps-print-n-up
)
1507 (defcustom ps-number-of-columns
(if ps-landscape-mode
2 1)
1508 "*Specify the number of columns"
1510 :group
'ps-print-miscellany
)
1512 (defcustom ps-zebra-stripes nil
1513 "*Non-nil means print zebra stripes.
1514 See also documentation for `ps-zebra-stripe-height' and `ps-zebra-color'."
1516 :group
'ps-print-zebra
)
1518 (defcustom ps-zebra-stripe-height
3
1519 "*Number of zebra stripe lines.
1520 See also documentation for `ps-zebra-stripes' and `ps-zebra-color'."
1522 :group
'ps-print-zebra
)
1524 (defcustom ps-zebra-color
0.95
1525 "*Zebra stripe gray scale or RGB color.
1526 See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
1527 :type
'(choice :tag
"Zebra Gray/Color"
1528 (number :tag
"Gray Scale" :value
0.95)
1529 (string :tag
"Color Name" :value
"gray95")
1530 (list :tag
"RGB Color" :value
(0.95
0.95 0.95)
1532 (number :tag
"Green")
1533 (number :tag
"Blue")))
1534 :group
'ps-print-zebra
)
1536 (defcustom ps-line-number nil
1537 "*Non-nil means print line number."
1539 :group
'ps-print-miscellany
)
1541 (defcustom ps-print-background-image nil
1542 "*EPS image list to be printed on background.
1546 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1548 FILENAME is a file name which contains an EPS image or some PostScript
1549 programming like EPS.
1550 FILENAME is ignored, if it doesn't exist or is read protected.
1552 X and Y are relative positions on paper to put the image.
1553 If X and Y are nil, the image is centralized on paper.
1555 XSCALE and YSCALE are scale factor to be applied to image before printing.
1556 If XSCALE and YSCALE are nil, the original size is used.
1558 ROTATION is the image rotation angle; if nil, the default is 0.
1560 PAGES designates the page to print background image.
1561 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1563 If PAGES is nil, print background image on all pages.
1565 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1566 an integer number or a string. If it is a string, the string should contain
1567 PostScript programming that returns a float or integer value.
1569 For example, if you wish to print an EPS image on all pages do:
1571 '((\"~/images/EPS-image.ps\"))"
1572 :type
'(repeat (list (file :tag
"EPS File")
1573 (choice :tag
"X" (const :tag
"default" nil
) number string
)
1574 (choice :tag
"Y" (const :tag
"default" nil
) number string
)
1575 (choice :tag
"X Scale" (const :tag
"default" nil
) number string
)
1576 (choice :tag
"Y Scale" (const :tag
"default" nil
) number string
)
1577 (choice :tag
"Rotation" (const :tag
"default" nil
) number string
)
1578 (repeat :tag
"Pages" :inline t
1579 (radio (integer :tag
"Page")
1581 (integer :tag
"From")
1582 (integer :tag
"To"))))))
1583 :group
'ps-print-background
)
1585 (defcustom ps-print-background-text nil
1586 "*Text list to be printed on background.
1590 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1592 STRING is the text to be printed on background.
1594 X and Y are positions on paper to put the text.
1595 If X and Y are nil, the text is positioned at lower left corner.
1597 FONT is a font name to be used on printing the text.
1598 If nil, \"Times-Roman\" is used.
1600 FONTSIZE is font size to be used, if nil, 200 is used.
1602 GRAY is the text gray factor (should be very light like 0.8).
1603 If nil, the default is 0.85.
1605 ROTATION is the text rotation angle; if nil, the angle is given by
1606 the diagonal from lower left corner to upper right corner.
1608 PAGES designates the page to print background text.
1609 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1611 If PAGES is nil, print background text on all pages.
1613 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1614 an integer number or a string. If it is a string, the string should contain
1615 PostScript programming that returns a float or integer value.
1617 For example, if you wish to print text \"Preliminary\" on all pages do:
1619 '((\"Preliminary\"))"
1620 :type
'(repeat (list (string :tag
"Text")
1621 (choice :tag
"X" (const :tag
"default" nil
) number string
)
1622 (choice :tag
"Y" (const :tag
"default" nil
) number string
)
1623 (choice :tag
"Font" (const :tag
"default" nil
) string
)
1624 (choice :tag
"Fontsize" (const :tag
"default" nil
) number string
)
1625 (choice :tag
"Gray" (const :tag
"default" nil
) number string
)
1626 (choice :tag
"Rotation" (const :tag
"default" nil
) number string
)
1627 (repeat :tag
"Pages" :inline t
1628 (radio (integer :tag
"Page")
1630 (integer :tag
"From")
1631 (integer :tag
"To"))))))
1632 :group
'ps-print-background
)
1634 ;;; Horizontal layout
1636 ;; ------------------------------------------
1638 ;; | lm | text | ic | text | ic | text | rm |
1640 ;; ------------------------------------------
1642 (defcustom ps-left-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1643 "*Left margin in points (1/72 inch)."
1645 :group
'ps-print-horizontal
)
1647 (defcustom ps-right-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1648 "*Right margin in points (1/72 inch)."
1650 :group
'ps-print-horizontal
)
1652 (defcustom ps-inter-column
(/ (* 72 2.0) 2.54) ; 2 cm
1653 "*Horizontal space between columns in points (1/72 inch)."
1655 :group
'ps-print-horizontal
)
1671 (defcustom ps-bottom-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1672 "*Bottom margin in points (1/72 inch)."
1674 :group
'ps-print-vertical
)
1676 (defcustom ps-top-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1677 "*Top margin in points (1/72 inch)."
1679 :group
'ps-print-vertical
)
1681 (defcustom ps-header-offset
(/ (* 72 1.0) 2.54) ; 1.0 cm
1682 "*Vertical space in points (1/72 inch) between the main text and the header."
1684 :group
'ps-print-vertical
)
1686 (defcustom ps-header-line-pad
0.15
1687 "*Portion of a header title line height to insert between the header frame
1688 and the text it contains, both in the vertical and horizontal directions."
1690 :group
'ps-print-vertical
)
1694 (defcustom ps-print-header t
1695 "*Non-nil means print a header at the top of each page.
1696 By default, the header displays the buffer name, page number, and, if
1697 the buffer is visiting a file, the file's directory. Headers are
1698 customizable by changing variables `ps-left-header' and
1701 :group
'ps-print-headers
)
1703 (defcustom ps-print-only-one-header nil
1704 "*Non-nil means print only one header at the top of each page.
1705 This is useful when printing more than one column, so it is possible
1706 to have only one header over all columns or one header per column.
1707 See also `ps-print-header'."
1709 :group
'ps-print-headers
)
1711 (defcustom ps-print-header-frame t
1712 "*Non-nil means draw a gaudy frame around the header."
1714 :group
'ps-print-headers
)
1716 (defcustom ps-header-lines
2
1717 "*Number of lines to display in page header, when generating PostScript."
1719 :group
'ps-print-headers
)
1721 (defcustom ps-show-n-of-n t
1722 "*Non-nil means show page numbers as N/M, meaning page N of M.
1723 NOTE: page numbers are displayed as part of headers,
1724 see variable `ps-print-header'."
1726 :group
'ps-print-headers
)
1728 (defcustom ps-spool-config
(if (memq system-type
1729 '(win32 w32 mswindows ms-dos windows-nt
))
1732 "*Specify who is responsable for setting duplex and page size switches.
1736 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
1737 Don't forget to set `ps-lpr-switches' to select duplex
1738 printing for your printer.
1740 `setpagedevice' duplex and page size are configured by ps-print using the
1741 setpagedevice PostScript operator.
1743 nil duplex and page size are configured by ps-print *not* using
1744 the setpagedevice PostScript operator.
1746 Any other value is treated as nil.
1748 WARNING: The setpagedevice PostScript operator affects ghostview utility when
1749 viewing file generated using landscape. Also on some printers,
1750 setpagedevice affects zebra stripes; on other printers, setpagedevice
1751 affects the left margin.
1752 Besides all that, if your printer does not have the paper size
1753 specified by setpagedevice, your printing will be aborted.
1754 So, if you need to use setpagedevice, set `ps-spool-config' to
1755 `setpagedevice', generate a test file and send it to your printer; if
1756 the printed file isn't ok, set `ps-spool-config' to nil."
1757 :type
'(choice :tag
"Spool Config"
1758 (const lpr-switches
) (const setpagedevice
)
1759 (other :tag
"nil" nil
))
1760 :group
'ps-print-headers
)
1762 (defcustom ps-spool-duplex nil
; Not many people have duplex printers,
1763 ; so default to nil.
1764 "*Non-nil generates PostScript for a two-sided printer.
1765 For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
1766 blank pages as needed between print jobs so that the next buffer printed will
1767 start on the right page. Also, if headers are turned on, the headers will be
1768 reversed on duplex printers so that the page numbers fall to the left on
1769 even-numbered pages.
1771 See also `ps-spool-tumble'."
1773 :group
'ps-print-headers
)
1775 (defcustom ps-spool-tumble nil
1776 "*Specify how the page images on opposite sides of a sheet are oriented.
1777 If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
1778 right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
1781 It has effect only when `ps-spool-duplex' is non-nil."
1783 :group
'ps-print-headers
)
1787 (defcustom ps-font-info-database
1788 '((Courier ; the family key
1789 (fonts (normal .
"Courier")
1790 (bold .
"Courier-Bold")
1791 (italic .
"Courier-Oblique")
1792 (bold-italic .
"Courier-BoldOblique"))
1794 (line-height .
10.55)
1796 (avg-char-width .
6.0))
1797 (Helvetica ; the family key
1798 (fonts (normal .
"Helvetica")
1799 (bold .
"Helvetica-Bold")
1800 (italic .
"Helvetica-Oblique")
1801 (bold-italic .
"Helvetica-BoldOblique"))
1803 (line-height .
11.56)
1804 (space-width .
2.78)
1805 (avg-char-width .
5.09243))
1807 (fonts (normal .
"Times-Roman")
1808 (bold .
"Times-Bold")
1809 (italic .
"Times-Italic")
1810 (bold-italic .
"Times-BoldItalic"))
1812 (line-height .
11.0)
1814 (avg-char-width .
4.71432))
1816 (fonts (normal .
"Palatino-Roman")
1817 (bold .
"Palatino-Bold")
1818 (italic .
"Palatino-Italic")
1819 (bold-italic .
"Palatino-BoldItalic"))
1821 (line-height .
12.1)
1823 (avg-char-width .
5.08676))
1825 (fonts (normal .
"Helvetica-Narrow")
1826 (bold .
"Helvetica-Narrow-Bold")
1827 (italic .
"Helvetica-Narrow-Oblique")
1828 (bold-italic .
"Helvetica-Narrow-BoldOblique"))
1830 (line-height .
11.56)
1831 (space-width .
2.2796)
1832 (avg-char-width .
4.17579))
1834 (fonts (normal .
"NewCenturySchlbk-Roman")
1835 (bold .
"NewCenturySchlbk-Bold")
1836 (italic .
"NewCenturySchlbk-Italic")
1837 (bold-italic .
"NewCenturySchlbk-BoldItalic"))
1839 (line-height .
12.15)
1840 (space-width .
2.78)
1841 (avg-char-width .
5.31162))
1842 ;; got no bold for the next ones
1844 (fonts (normal .
"AvantGarde-Book")
1845 (italic .
"AvantGarde-BookOblique"))
1847 (line-height .
11.77)
1848 (space-width .
2.77)
1849 (avg-char-width .
5.45189))
1851 (fonts (normal .
"AvantGarde-Demi")
1852 (italic .
"AvantGarde-DemiOblique"))
1854 (line-height .
12.72)
1856 (avg-char-width .
5.51351))
1858 (fonts (normal .
"Bookman-Demi")
1859 (italic .
"Bookman-DemiItalic"))
1861 (line-height .
11.77)
1863 (avg-char-width .
6.05946))
1865 (fonts (normal .
"Bookman-Light")
1866 (italic .
"Bookman-LightItalic"))
1868 (line-height .
11.79)
1870 (avg-char-width .
5.67027))
1871 ;; got no bold and no italic for the next ones
1873 (fonts (normal .
"Symbol"))
1875 (line-height .
13.03)
1877 (avg-char-width .
3.24324))
1879 (fonts (normal .
"Zapf-Dingbats"))
1881 (line-height .
9.63)
1882 (space-width .
2.78)
1883 (avg-char-width .
2.78))
1884 (Zapf-Chancery-MediumItalic
1885 (fonts (normal .
"Zapf-Chancery-MediumItalic"))
1887 (line-height .
11.45)
1889 (avg-char-width .
4.10811))
1891 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1892 reference size, line height, space width, average character width.
1893 To get the info for another specific font (say Helvetica), do the following:
1894 - create a new buffer
1895 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
1896 - open this file and delete the leading `%' (which is the PostScript
1897 comment character) from the line
1898 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
1900 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
1901 - add the values to `ps-font-info-database'.
1902 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
1903 :type
'(repeat (list :tag
"Font Definition"
1904 (symbol :tag
"Font Family")
1906 (const :format
"" fonts
)
1907 (repeat :tag
"Faces"
1908 (cons (choice (const normal
)
1912 (symbol :tag
"Face"))
1913 (string :tag
"Font Name"))))
1915 (const :format
"" size
)
1916 (number :tag
"Reference Size"))
1918 (const :format
"" line-height
)
1919 (number :tag
"Line Height"))
1921 (const :format
"" space-width
)
1922 (number :tag
"Space Width"))
1924 (const :format
"" avg-char-width
)
1925 (number :tag
"Average Character Width"))))
1926 :group
'ps-print-font
)
1928 (defcustom ps-font-family
'Courier
1929 "*Font family name for ordinary text, when generating PostScript."
1931 :group
'ps-print-font
)
1933 (defcustom ps-font-size
'(7 .
8.5)
1934 "*Font size, in points, for ordinary text, when generating PostScript."
1935 :type
'(choice (number :tag
"Text Size")
1936 (cons :tag
"Landscape/Portrait"
1937 (number :tag
"Landscape Text Size")
1938 (number :tag
"Portrait Text Size")))
1939 :group
'ps-print-font
)
1941 (defcustom ps-header-font-family
'Helvetica
1942 "*Font family name for text in the header, when generating PostScript."
1944 :group
'ps-print-font
)
1946 (defcustom ps-header-font-size
'(10 .
12)
1947 "*Font size, in points, for text in the header, when generating PostScript."
1948 :type
'(choice (number :tag
"Header Size")
1949 (cons :tag
"Landscape/Portrait"
1950 (number :tag
"Landscape Header Size")
1951 (number :tag
"Portrait Header Size")))
1952 :group
'ps-print-font
)
1954 (defcustom ps-header-title-font-size
'(12 .
14)
1955 "*Font size, in points, for the top line of text in header, in PostScript."
1956 :type
'(choice (number :tag
"Header Title Size")
1957 (cons :tag
"Landscape/Portrait"
1958 (number :tag
"Landscape Header Title Size")
1959 (number :tag
"Portrait Header Title Size")))
1960 :group
'ps-print-font
)
1964 ;; Printing color requires x-color-values.
1965 (defcustom ps-print-color-p
(or (fboundp 'x-color-values
) ; Emacs
1966 (fboundp 'color-instance-rgb-components
))
1968 "*Non-nil means print the buffer's text in color."
1970 :group
'ps-print-color
)
1972 (defcustom ps-default-fg
'(0.0
0.0 0.0)
1973 "*RGB values of the default foreground color. Defaults to black."
1974 :type
'(choice :tag
"Default Foreground Gray/Color"
1975 (number :tag
"Gray Scale" :value
0.0)
1976 (string :tag
"Color Name" :value
"black")
1977 (list :tag
"RGB Color" :value
(0.0
0.0 0.0)
1979 (number :tag
"Green")
1980 (number :tag
"Blue")))
1981 :group
'ps-print-color
)
1983 (defcustom ps-default-bg
'(1.0
1.0 1.0)
1984 "*RGB values of the default background color. Defaults to white."
1985 :type
'(choice :tag
"Default Background Gray/Color"
1986 (number :tag
"Gray Scale" :value
1.0)
1987 (string :tag
"Color Name" :value
"white")
1988 (list :tag
"RGB Color" :value
(1.0
1.0 1.0)
1990 (number :tag
"Green")
1991 (number :tag
"Blue")))
1992 :group
'ps-print-color
)
1994 (defcustom ps-auto-font-detect t
1995 "*Non-nil means automatically detect bold/italic face attributes.
1996 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
1997 and `ps-underlined-faces'."
1999 :group
'ps-print-font
)
2001 (defcustom ps-bold-faces
2002 (unless ps-print-color-p
2003 '(font-lock-function-name-face
2004 font-lock-builtin-face
2005 font-lock-variable-name-face
2006 font-lock-keyword-face
2007 font-lock-warning-face
))
2008 "*A list of the \(non-bold\) faces that should be printed in bold font.
2009 This applies to generating PostScript."
2010 :type
'(repeat face
)
2011 :group
'ps-print-face
)
2013 (defcustom ps-italic-faces
2014 (unless ps-print-color-p
2015 '(font-lock-variable-name-face
2017 font-lock-string-face
2018 font-lock-comment-face
2019 font-lock-warning-face
))
2020 "*A list of the \(non-italic\) faces that should be printed in italic font.
2021 This applies to generating PostScript."
2022 :type
'(repeat face
)
2023 :group
'ps-print-face
)
2025 (defcustom ps-underlined-faces
2026 (unless ps-print-color-p
2027 '(font-lock-function-name-face
2028 font-lock-constant-face
2029 font-lock-warning-face
))
2030 "*A list of the \(non-underlined\) faces that should be printed underlined.
2031 This applies to generating PostScript."
2032 :type
'(repeat face
)
2033 :group
'ps-print-face
)
2035 (defcustom ps-left-header
2036 (list 'ps-get-buffer-name
'ps-header-dirpart
)
2037 "*The items to display (each on a line) on the left part of the page header.
2038 This applies to generating PostScript.
2040 The value should be a list of strings and symbols, each representing an
2041 entry in the PostScript array HeaderLinesLeft.
2043 Strings are inserted unchanged into the array; those representing
2044 PostScript string literals should be delimited with PostScript string
2045 delimiters '(' and ')'.
2047 For symbols with bound functions, the function is called and should
2048 return a string to be inserted into the array. For symbols with bound
2049 values, the value should be a string to be inserted into the array.
2050 In either case, function or variable, the string value has PostScript
2051 string delimiters added to it."
2052 :type
'(repeat (choice string symbol
))
2053 :group
'ps-print-headers
)
2055 (defcustom ps-right-header
2056 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy
'time-stamp-hh
:mm
:ss
)
2057 "*The items to display (each on a line) on the right part of the page header.
2058 This applies to generating PostScript.
2060 See the variable `ps-left-header' for a description of the format of
2062 :type
'(repeat (choice string symbol
))
2063 :group
'ps-print-headers
)
2065 (defcustom ps-razzle-dazzle t
2066 "*Non-nil means report progress while formatting buffer."
2068 :group
'ps-print-miscellany
)
2070 (defcustom ps-adobe-tag
"%!PS-Adobe-3.0\n"
2071 "*Contains the header line identifying the output as PostScript.
2072 By default, `ps-adobe-tag' contains the standard identifier. Some
2073 printers require slightly different versions of this line."
2075 :group
'ps-print-miscellany
)
2077 (defcustom ps-build-face-reference t
2078 "*Non-nil means build the reference face lists.
2080 ps-print sets this value to nil after it builds its internal reference
2081 lists of bold and italic faces. By settings its value back to t, you
2082 can force ps-print to rebuild the lists the next time you invoke one
2083 of the ...-with-faces commands.
2085 You should set this value back to t after you change the attributes of
2086 any face, or create new faces. Most users shouldn't have to worry
2087 about its setting, though."
2089 :group
'ps-print-face
)
2091 (defcustom ps-always-build-face-reference nil
2092 "*Non-nil means always rebuild the reference face lists.
2094 If this variable is non-nil, ps-print will rebuild its internal
2095 reference lists of bold and italic faces *every* time one of the
2096 ...-with-faces commands is called. Most users shouldn't need to set this
2099 :group
'ps-print-face
)
2101 (defcustom ps-banner-page-when-duplexing nil
2102 "*Non-nil means the very first page is skipped.
2103 It's like the very first character of buffer (or region) is ^L (\\014)."
2105 :group
'ps-print-headers
)
2107 (defcustom ps-postscript-code-directory data-directory
2108 "*Directory where it's located the PostScript prologue file used by ps-print.
2109 By default, this directory is the same as in the variable `data-directory'."
2111 :group
'ps-print-miscellany
)
2114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2119 (defun ps-print-customize ()
2120 "Customization of ps-print group."
2122 (customize-group 'ps-print
))
2125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2130 (defun ps-print-buffer (&optional filename
)
2131 "Generate and print a PostScript image of the buffer.
2133 Interactively, when you use a prefix argument (C-u), the command
2134 prompts the user for a file name, and saves the PostScript image
2135 in that file instead of sending it to the printer.
2137 Noninteractively, the argument FILENAME is treated as follows: if it
2138 is nil, send the image to the printer. If FILENAME is a string, save
2139 the PostScript image in a file with that name."
2140 (interactive (list (ps-print-preprint current-prefix-arg
)))
2141 (ps-print-without-faces (point-min) (point-max) filename
))
2145 (defun ps-print-buffer-with-faces (&optional filename
)
2146 "Generate and print a PostScript image of the buffer.
2147 Like `ps-print-buffer', but includes font, color, and underline
2148 information in the generated image. This command works only if you
2149 are using a window system, so it has a way to determine color values."
2150 (interactive (list (ps-print-preprint current-prefix-arg
)))
2151 (ps-print-with-faces (point-min) (point-max) filename
))
2155 (defun ps-print-region (from to
&optional filename
)
2156 "Generate and print a PostScript image of the region.
2157 Like `ps-print-buffer', but prints just the current region."
2158 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2159 (ps-print-without-faces from to filename t
))
2163 (defun ps-print-region-with-faces (from to
&optional filename
)
2164 "Generate and print a PostScript image of the region.
2165 Like `ps-print-region', but includes font, color, and underline
2166 information in the generated image. This command works only if you
2167 are using a window system, so it has a way to determine color values."
2168 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2169 (ps-print-with-faces from to filename t
))
2173 (defun ps-spool-buffer ()
2174 "Generate and spool a PostScript image of the buffer.
2175 Like `ps-print-buffer' except that the PostScript image is saved in a
2176 local buffer to be sent to the printer later.
2178 Use the command `ps-despool' to send the spooled images to the printer."
2180 (ps-spool-without-faces (point-min) (point-max)))
2184 (defun ps-spool-buffer-with-faces ()
2185 "Generate and spool a PostScript image of the buffer.
2186 Like `ps-spool-buffer', but includes font, color, and underline
2187 information in the generated image. This command works only if you
2188 are using a window system, so it has a way to determine color values.
2190 Use the command `ps-despool' to send the spooled images to the printer."
2192 (ps-spool-with-faces (point-min) (point-max)))
2196 (defun ps-spool-region (from to
)
2197 "Generate a PostScript image of the region and spool locally.
2198 Like `ps-spool-buffer', but spools just the current region.
2200 Use the command `ps-despool' to send the spooled images to the printer."
2202 (ps-spool-without-faces from to t
))
2206 (defun ps-spool-region-with-faces (from to
)
2207 "Generate a PostScript image of the region and spool locally.
2208 Like `ps-spool-region', but includes font, color, and underline
2209 information in the generated image. This command works only if you
2210 are using a window system, so it has a way to determine color values.
2212 Use the command `ps-despool' to send the spooled images to the printer."
2214 (ps-spool-with-faces from to t
))
2217 (defun ps-despool (&optional filename
)
2218 "Send the spooled PostScript to the printer.
2220 Interactively, when you use a prefix argument (C-u), the command
2221 prompts the user for a file name, and saves the spooled PostScript
2222 image in that file instead of sending it to the printer.
2224 Noninteractively, the argument FILENAME is treated as follows: if it
2225 is nil, send the image to the printer. If FILENAME is a string, save
2226 the PostScript image in a file with that name."
2227 (interactive (list (ps-print-preprint current-prefix-arg
)))
2228 (ps-do-despool filename
))
2231 (defun ps-line-lengths ()
2232 "Display the correspondence between a line length and a font size,
2233 using the current ps-print setup.
2234 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2236 (ps-line-lengths-internal))
2239 (defun ps-nb-pages-buffer (nb-lines)
2240 "Display number of pages to print this buffer, for various font heights.
2241 The table depends on the current ps-print setup."
2242 (interactive (list (count-lines (point-min) (point-max))))
2243 (ps-nb-pages nb-lines
))
2246 (defun ps-nb-pages-region (nb-lines)
2247 "Display number of pages to print the region, for various font heights.
2248 The table depends on the current ps-print setup."
2249 (interactive (list (count-lines (mark) (point))))
2250 (ps-nb-pages nb-lines
))
2254 "Return the current PostScript-generation setup."
2257 \(setq ps-print-color-p %s
2261 ps-print-region-function %s
2264 ps-landscape-mode %s
2265 ps-number-of-columns %s
2268 ps-zebra-stripe-height %s
2275 ps-print-control-characters %s
2277 ps-print-background-image %s
2279 ps-print-background-text %s
2281 ps-error-handler-message %s
2282 ps-user-defined-prologue %s
2283 ps-print-prologue-header %s
2291 ps-header-line-pad %s
2293 ps-print-only-one-header %s
2294 ps-print-header-frame %s
2300 ps-banner-page-when-duplexing %s
2307 ps-multibyte-buffer %s
2310 ps-header-font-family %s
2311 ps-header-font-size %s
2312 ps-header-title-font-size %s)
2316 (ps-print-quote ps-lpr-switches
)
2318 (ps-print-quote ps-print-region-function
)
2319 (ps-print-quote ps-paper-type
)
2321 ps-number-of-columns
2323 ps-zebra-stripe-height
2324 (ps-print-quote ps-zebra-color
)
2326 (ps-print-quote ps-default-fg
)
2327 (ps-print-quote ps-default-bg
)
2328 (ps-print-quote ps-print-control-characters
)
2329 (ps-print-quote ps-print-background-image
)
2330 (ps-print-quote ps-print-background-text
)
2331 (ps-print-quote ps-error-handler-message
)
2332 (ps-print-quote ps-user-defined-prologue
)
2333 (ps-print-quote ps-print-prologue-header
)
2342 ps-print-only-one-header
2343 ps-print-header-frame
2346 (ps-print-quote ps-spool-config
)
2349 ps-banner-page-when-duplexing
2353 (ps-print-quote ps-n-up-filling
)
2354 (ps-print-quote ps-multibyte-buffer
) ; see `ps-mule.el'
2355 (ps-print-quote ps-font-family
)
2356 (ps-print-quote ps-font-size
)
2357 (ps-print-quote ps-header-font-family
)
2358 (ps-print-quote ps-header-font-size
)
2359 (ps-print-quote ps-header-title-font-size
)))
2362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2363 ;; Utility functions and variables:
2366 (defun ps-print-quote (sym)
2369 ((or (symbolp sym
) (listp sym
))
2376 (defvar ps-print-emacs-type
2377 (cond ((string-match "XEmacs" emacs-version
) 'xemacs
)
2378 ((string-match "Lucid" emacs-version
) 'lucid
)
2379 ((string-match "Epoch" emacs-version
) 'epoch
)
2382 (if (or (eq ps-print-emacs-type
'lucid
)
2383 (eq ps-print-emacs-type
'xemacs
))
2384 (if (< emacs-minor-version
12)
2385 (setq ps-print-color-p nil
))
2386 (require 'faces
)) ; face-font, face-underline-p,
2389 ;; Return t if the device (which can be changed during an emacs session)
2390 ;; can handle colors.
2391 ;; This is function is not yet implemented for GNU emacs.
2392 (cond ((and (eq ps-print-emacs-type
'xemacs
)
2393 (>= emacs-minor-version
12)) ; xemacs
2394 (defun ps-color-device ()
2395 (eq (device-class) 'color
))
2399 (defun ps-color-device ()
2404 (require 'time-stamp
)
2407 (defun ps-prologue-file (filenumber)
2410 (or (find-file-noselect
2411 (format "%sps-prin%d.ps"
2412 ps-postscript-code-directory filenumber
)
2414 (error "ps-print PostScript prologue %d file was not found."
2419 (kill-buffer buffer
)))))
2422 (defvar ps-mark-code-directory nil
)
2424 (defvar ps-print-prologue-0
""
2425 "ps-print PostScript error handler.")
2427 (defvar ps-print-prologue-1
""
2428 "ps-print PostScript prologue begin.")
2430 (defvar ps-print-prologue-2
""
2431 "ps-print PostScript prologue end.")
2433 (defvar ps-print-duplex-feature
""
2434 "ps-print PostScript duplex feature.")
2436 ;; Start Editing Here:
2438 (defvar ps-source-buffer nil
)
2439 (defvar ps-spool-buffer-name
"*PostScript*")
2440 (defvar ps-spool-buffer nil
)
2442 (defvar ps-output-head nil
)
2443 (defvar ps-output-tail nil
)
2445 (defvar ps-page-postscript
0)
2446 (defvar ps-page-order
0)
2447 (defvar ps-page-count
0)
2448 (defvar ps-showline-count
1)
2450 (defvar ps-control-or-escape-regexp nil
)
2452 (defvar ps-background-pages nil
)
2453 (defvar ps-background-all-pages nil
)
2454 (defvar ps-background-text-count
0)
2455 (defvar ps-background-image-count
0)
2457 (defvar ps-current-font
0)
2458 (defvar ps-default-foreground nil
)
2459 (defvar ps-default-color nil
)
2460 (defvar ps-current-color nil
)
2461 (defvar ps-current-bg nil
)
2463 (defvar ps-razchunk
0)
2465 (defvar ps-color-p nil
)
2466 (defvar ps-color-format
2467 (if (eq ps-print-emacs-type
'emacs
)
2469 ;; Emacs understands the %f format; we'll use it to limit color RGB
2470 ;; values to three decimals to cut down some on the size of the
2471 ;; PostScript output.
2474 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2477 ;; These values determine how much print-height to deduct when headers
2478 ;; are turned on. This is a pretty clumsy way of handling it, but
2479 ;; it'll do for now.
2481 (defvar ps-header-pad
0
2482 "Vertical and horizontal space between the header frame and the text.
2483 This is in units of points (1/72 inch).")
2485 ;; Define accessors to the dimensions list.
2487 (defmacro ps-page-dimensions-get-width
(dims) `(nth 0 ,dims
))
2488 (defmacro ps-page-dimensions-get-height
(dims) `(nth 1 ,dims
))
2489 (defmacro ps-page-dimensions-get-media
(dims) `(nth 2 ,dims
))
2491 (defvar ps-landscape-page-height nil
)
2493 (defvar ps-print-width nil
)
2494 (defvar ps-print-height nil
)
2496 (defvar ps-height-remaining nil
)
2497 (defvar ps-width-remaining nil
)
2499 (defvar ps-print-color-scale nil
)
2501 (defvar ps-font-size-internal nil
)
2502 (defvar ps-header-font-size-internal nil
)
2503 (defvar ps-header-title-font-size-internal nil
)
2506 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2507 ;; Internal Variables
2510 (defvar ps-print-face-extension-alist nil
2511 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2512 An element of this list has the following form:
2514 (FACE . [BITS FG BG])
2516 FACE is a symbol denoting a face name
2517 BITS is a bit vector, where each bit correspond
2518 to a feature (bold, underline, etc)
2519 (see documentation for `ps-print-face-map-alist')
2520 FG foreground color (string or nil)
2521 BG background color (string or nil)
2523 Don't change this list directly; instead,
2524 use `ps-extend-face' and `ps-extend-face-list'.
2525 See documentation for `ps-extend-face' for valid extension symbol.")
2528 (defvar ps-print-face-alist nil
2529 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2531 An element of this list has the same form as an element of
2532 `ps-print-face-extension-alist'.
2534 Don't change this list directly; this list is used by `ps-face-attributes',
2535 `ps-map-face' and `ps-build-reference-face-lists'.")
2538 (defconst ps-print-face-map-alist
2547 "Alist of all features and the corresponding bit mask.
2548 Each symbol correspond to one bit in a bit vector.")
2551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2556 (defun ps-extend-face-list (face-extension-list &optional merge-p
)
2557 "Extend face in `ps-print-face-extension-alist'.
2559 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2560 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2562 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2564 See `ps-extend-face' for documentation."
2565 (while face-extension-list
2566 (ps-extend-face (car face-extension-list
) merge-p
)
2567 (setq face-extension-list
(cdr face-extension-list
))))
2571 (defun ps-extend-face (face-extension &optional merge-p
)
2572 "Extend face in `ps-print-face-extension-alist'.
2574 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2575 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2577 The elements of FACE-EXTENSION list have the form:
2579 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2581 FACE-NAME is a face name symbol.
2583 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2584 foreground and background colors respectively.
2586 EXTENSION is one of the following symbols:
2587 bold - use bold font.
2588 italic - use italic font.
2589 underline - put a line under text.
2590 strikeout - like underline, but the line is in middle of text.
2591 overline - like underline, but the line is over the text.
2592 shadow - text will have a shadow.
2593 box - text will be surrounded by a box.
2594 outline - print characters as hollow outlines.
2596 If EXTENSION is any other symbol, it is ignored."
2597 (let* ((face-name (nth 0 face-extension
))
2598 (foreground (nth 1 face-extension
))
2599 (background (nth 2 face-extension
))
2600 (ps-face (cdr (assq face-name ps-print-face-extension-alist
)))
2601 (face-vector (or ps-face
(vector 0 nil nil
)))
2602 (face-bit (ps-extension-bit face-extension
)))
2604 (aset face-vector
0 (if merge-p
2605 (logior (aref face-vector
0) face-bit
)
2607 (and foreground
(stringp foreground
) (aset face-vector
1 foreground
))
2608 (and background
(stringp background
) (aset face-vector
2 background
))
2609 ;; if face does not exist, insert it
2611 (setq ps-print-face-extension-alist
2612 (cons (cons face-name face-vector
)
2613 ps-print-face-extension-alist
)))))
2616 (defun ps-extension-bit (face-extension)
2618 ;; map valid symbol extension to bit vector
2619 (setq face-extension
(cdr (cdr face-extension
)))
2620 (while (setq face-extension
(cdr face-extension
))
2621 (setq face-bit
(logior face-bit
2622 (or (cdr (assq (car face-extension
)
2623 ps-print-face-map-alist
))
2628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2629 ;; Adapted from font-lock: (obsolete stuff)
2630 ;; Originally face attributes were specified via `font-lock-face-attributes'.
2631 ;; Users then changed the default face attributes by setting that variable.
2632 ;; However, we try and be back-compatible and respect its value if set except
2633 ;; for faces where M-x customize has been used to save changes for the face.
2636 (defun ps-font-lock-face-attributes ()
2637 (and (boundp 'font-lock-mode
) (symbol-value 'font-lock-mode
)
2638 (boundp 'font-lock-face-attributes
)
2639 (let ((face-attributes font-lock-face-attributes
))
2640 (while face-attributes
2641 (let* ((face-attribute
2642 (car (prog1 face-attributes
2643 (setq face-attributes
(cdr face-attributes
)))))
2644 (face (car face-attribute
)))
2645 ;; Rustle up a `defface' SPEC from a
2646 ;; `font-lock-face-attributes' entry.
2647 (unless (get face
'saved-face
)
2648 (let ((foreground (nth 1 face-attribute
))
2649 (background (nth 2 face-attribute
))
2650 (bold-p (nth 3 face-attribute
))
2651 (italic-p (nth 4 face-attribute
))
2652 (underline-p (nth 5 face-attribute
))
2655 (setq face-spec
(cons ':foreground
2656 (cons foreground face-spec
))))
2658 (setq face-spec
(cons ':background
2659 (cons background face-spec
))))
2661 (setq face-spec
(append '(:bold t
) face-spec
)))
2663 (setq face-spec
(append '(:italic t
) face-spec
)))
2665 (setq face-spec
(append '(:underline t
) face-spec
)))
2666 (custom-declare-face face
(list (list t face-spec
)) nil
)
2670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2671 ;; Internal functions and variables
2674 (make-local-hook 'ps-print-hook
)
2675 (make-local-hook 'ps-print-begin-sheet-hook
)
2676 (make-local-hook 'ps-print-begin-page-hook
)
2677 (make-local-hook 'ps-print-begin-column-hook
)
2680 (defun ps-print-without-faces (from to
&optional filename region-p
)
2681 (ps-spool-without-faces from to region-p
)
2682 (ps-do-despool filename
))
2685 (defun ps-spool-without-faces (from to
&optional region-p
)
2686 (run-hooks 'ps-print-hook
)
2687 (ps-printing-region region-p
)
2688 (ps-generate (current-buffer) from to
'ps-generate-postscript
))
2691 (defun ps-print-with-faces (from to
&optional filename region-p
)
2692 (ps-spool-with-faces from to region-p
)
2693 (ps-do-despool filename
))
2696 (defun ps-spool-with-faces (from to
&optional region-p
)
2697 (run-hooks 'ps-print-hook
)
2698 (ps-printing-region region-p
)
2699 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
))
2702 (defun ps-count-lines (from to
)
2703 (+ (count-lines from to
)
2706 (if (= (current-column) 0) 1 0))))
2709 (defvar ps-printing-region nil
2710 "Variable used to indicate if the region that ps-print is printing.
2711 It is a cons, the car of which is the line number where the region begins, and
2712 its cdr is the total number of lines in the buffer. Formatting functions can
2713 use this information to print the original line number (and not the number of
2714 lines printed), and to indicate in the header that the printout is of a partial
2718 (defvar ps-printing-region-p nil
2719 "Non-nil means ps-print is printing a region.")
2722 (defun ps-printing-region (region-p)
2723 (setq ps-printing-region-p region-p
2726 (ps-count-lines (point-min) (region-beginning))
2728 (ps-count-lines (point-min) (point-max)))))
2731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2732 ;; Internal functions
2735 (defsubst ps-font-alist
(font-sym)
2736 (get font-sym
'fonts
))
2738 (defun ps-font (font-sym font-type
)
2739 "Font family name for text of `font-type', when generating PostScript."
2740 (let* ((font-list (ps-font-alist font-sym
))
2741 (normal-font (cdr (assq 'normal font-list
))))
2742 (while (and font-list
(not (eq font-type
(car (car font-list
)))))
2743 (setq font-list
(cdr font-list
)))
2744 (or (cdr (car font-list
)) normal-font
)))
2746 (defun ps-fonts (font-sym)
2747 (mapcar 'cdr
(ps-font-alist font-sym
)))
2749 (defun ps-font-number (font-sym font-type
)
2750 (or (ps-alist-position font-type
(ps-font-alist font-sym
))
2753 (defsubst ps-line-height
(font-sym)
2754 "The height of a line, for generating PostScript.
2755 This is the value that ps-print uses to determine the height,
2756 y-dimension, of the lines of text it has printed, and thus affects the
2757 point at which page-breaks are placed.
2758 The line-height is *not* the same as the point size of the font."
2759 (get font-sym
'line-height
))
2761 (defsubst ps-title-line-height
(font-sym)
2762 "The height of a `title' line, for generating PostScript.
2763 This is the value that ps-print uses to determine the height,
2764 y-dimension, of the lines of text it has printed, and thus affects the
2765 point at which page-breaks are placed.
2766 The title-line-height is *not* the same as the point size of the font."
2767 (get font-sym
'title-line-height
))
2769 (defsubst ps-space-width
(font-sym)
2770 "The width of a space character, for generating PostScript.
2771 This value is used in expanding tab characters."
2772 (get font-sym
'space-width
))
2774 (defsubst ps-avg-char-width
(font-sym)
2775 "The average width, in points, of a character, for generating PostScript.
2776 This is the value that ps-print uses to determine the length,
2777 x-dimension, of the text it has printed, and thus affects the point at
2778 which long lines wrap around."
2779 (get font-sym
'avg-char-width
))
2781 (defun ps-line-lengths-internal ()
2782 "Display the correspondence between a line length and a font size,
2783 using the current ps-print setup.
2784 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2785 (let ((buf (get-buffer-create "*Line-lengths*"))
2786 (ifs ps-font-size-internal
) ; initial font size
2787 (icw (ps-avg-char-width 'ps-font-for-text
)) ; initial character width
2788 (print-width (progn (ps-get-page-dimensions)
2790 (ps-setup (ps-setup)) ; setup for the current buffer
2791 (fs-min 5) ; minimum font size
2792 cw-min
; minimum character width
2793 nb-cpl-max
; maximum nb of characters per line
2794 (fs-max 14) ; maximum font size
2795 cw-max
; maximum character width
2796 nb-cpl-min
; minimum nb of characters per line
2797 fs
; current font size
2798 cw
; current character width
2799 nb-cpl
; current nb of characters per line
2801 (setq cw-min
(/ (* icw fs-min
) ifs
)
2802 nb-cpl-max
(floor (/ print-width cw-min
))
2803 cw-max
(/ (* icw fs-max
) ifs
)
2804 nb-cpl-min
(floor (/ print-width cw-max
))
2807 (goto-char (point-max))
2808 (or (bolp) (insert "\n"))
2810 "nb char per line / font size\n")
2811 (while (<= nb-cpl nb-cpl-max
)
2812 (setq cw
(/ print-width
(float nb-cpl
))
2813 fs
(/ (* ifs cw
) icw
))
2814 (insert (format "%3s %s\n" nb-cpl fs
))
2815 (setq nb-cpl
(1+ nb-cpl
)))
2817 (display-buffer buf
'not-this-window
)))
2819 (defun ps-nb-pages (nb-lines)
2820 "Display correspondence between font size and the number of pages.
2821 The correspondence is based on having NB-LINES lines of text,
2822 and on the current ps-print setup."
2823 (let ((buf (get-buffer-create "*Nb-Pages*"))
2824 (ifs ps-font-size-internal
) ; initial font size
2825 (ilh (ps-line-height 'ps-font-for-text
)) ; initial line height
2826 (page-height (progn (ps-get-page-dimensions)
2828 (ps-setup (ps-setup)) ; setup for the current buffer
2829 (fs-min 4) ; minimum font size
2830 lh-min
; minimum line height
2831 nb-lpp-max
; maximum nb of lines per page
2832 nb-page-min
; minimum nb of pages
2833 (fs-max 14) ; maximum font size
2834 lh-max
; maximum line height
2835 nb-lpp-min
; minimum nb of lines per page
2836 nb-page-max
; maximum nb of pages
2837 fs
; current font size
2838 lh
; current line height
2839 nb-lpp
; current nb of lines per page
2840 nb-page
; current nb of pages
2842 (setq lh-min
(/ (* ilh fs-min
) ifs
)
2843 nb-lpp-max
(floor (/ page-height lh-min
))
2844 nb-page-min
(ceiling (/ (float nb-lines
) nb-lpp-max
))
2845 lh-max
(/ (* ilh fs-max
) ifs
)
2846 nb-lpp-min
(floor (/ page-height lh-max
))
2847 nb-page-max
(ceiling (/ (float nb-lines
) nb-lpp-min
))
2848 nb-page nb-page-min
)
2850 (goto-char (point-max))
2851 (or (bolp) (insert "\n"))
2853 (format "%d lines\n" nb-lines
)
2854 "nb page / font size\n")
2855 (while (<= nb-page nb-page-max
)
2856 (setq nb-lpp
(ceiling (/ nb-lines
(float nb-page
)))
2857 lh
(/ page-height nb-lpp
)
2858 fs
(/ (* ifs lh
) ilh
))
2859 (insert (format "%s %s\n" nb-page fs
))
2860 (setq nb-page
(1+ nb-page
)))
2862 (display-buffer buf
'not-this-window
)))
2864 ;; macros used in `ps-select-font'
2865 (defmacro ps-lookup
(key) `(cdr (assq ,key font-entry
)))
2866 (defmacro ps-size-scale
(key) `(/ (* (ps-lookup ,key
) font-size
) size
))
2868 (defun ps-select-font (font-family sym font-size title-font-size
)
2869 (let ((font-entry (cdr (assq font-family ps-font-info-database
))))
2871 (error "Don't have data to scale font %s. Known fonts families are %s"
2873 (mapcar 'car ps-font-info-database
)))
2874 (let ((size (ps-lookup 'size
)))
2875 (put sym
'fonts
(ps-lookup 'fonts
))
2876 (put sym
'space-width
(ps-size-scale 'space-width
))
2877 (put sym
'avg-char-width
(ps-size-scale 'avg-char-width
))
2878 (put sym
'line-height
(ps-size-scale 'line-height
))
2879 (put sym
'title-line-height
2880 (/ (* (ps-lookup 'line-height
) title-font-size
) size
)))))
2882 (defun ps-get-page-dimensions ()
2883 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
2884 page-width page-height
)
2886 ((null page-dimensions
)
2887 (error "`ps-paper-type' must be one of:\n%s"
2888 (mapcar 'car ps-page-dimensions-database
)))
2889 ((< ps-number-of-columns
1)
2890 (error "The number of columns %d should be positive"
2891 ps-number-of-columns
)))
2893 (ps-select-font ps-font-family
'ps-font-for-text
2894 ps-font-size-internal ps-font-size-internal
)
2895 (ps-select-font ps-header-font-family
'ps-font-for-header
2896 ps-header-font-size-internal
2897 ps-header-title-font-size-internal
)
2899 (setq page-width
(ps-page-dimensions-get-width page-dimensions
)
2900 page-height
(ps-page-dimensions-get-height page-dimensions
))
2903 (if ps-landscape-mode
2904 ;; exchange width and height
2905 (setq page-width
(prog1 page-height
(setq page-height page-width
))))
2907 ;; It is used to get the lower right corner (only in landscape mode)
2908 (setq ps-landscape-page-height page-height
)
2910 ;; | lm | text | ic | text | ic | text | rm |
2911 ;; page-width == lm + n * pw + (n - 1) * ic + rm
2912 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
2913 (setq ps-print-width
(/ (- page-width
2914 ps-left-margin ps-right-margin
2915 (* (1- ps-number-of-columns
) ps-inter-column
))
2916 ps-number-of-columns
))
2917 (if (<= ps-print-width
0)
2918 (error "Bad horizontal layout:
2920 ps-left-margin == %s
2921 ps-right-margin == %s
2922 ps-inter-column == %s
2923 ps-number-of-columns == %s
2924 | lm | text | ic | text | ic | text | rm |
2925 page-width == lm + n * print-width + (n - 1) * ic + rm
2926 => print-width == %d !"
2931 ps-number-of-columns
2934 (setq ps-print-height
2935 (- page-height ps-bottom-margin ps-top-margin
))
2936 (if (<= ps-print-height
0)
2937 (error "Bad vertical layout:
2939 ps-bottom-margin == %s
2940 page-height == bm + print-height + tm
2941 => print-height == %d !"
2945 ;; If headers are turned on, deduct the height of the header from
2946 ;; the print height.
2948 (setq ps-header-pad
(* ps-header-line-pad
2949 (ps-title-line-height 'ps-font-for-header
))
2950 ps-print-height
(- ps-print-height
2953 (ps-title-line-height 'ps-font-for-header
)
2954 (* (ps-line-height 'ps-font-for-header
)
2955 (1- ps-header-lines
))
2957 (if (<= ps-print-height
0)
2958 (error "Bad vertical layout:
2960 ps-bottom-margin == %s
2961 ps-header-offset == %s
2964 page-height == bm + print-height + tm - ho - hh
2965 => print-height == %d !"
2971 (ps-title-line-height 'ps-font-for-header
)
2972 (* (ps-line-height 'ps-font-for-header
)
2973 (1- ps-header-lines
))
2977 (defun ps-print-preprint (&optional filename
)
2979 (or (numberp filename
)
2981 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
2984 (prompt (format "Save PostScript to file: (default %s) " name
))
2985 (res (read-file-name prompt default-directory name nil
)))
2986 (while (cond ((not (file-writable-p res
))
2988 (setq prompt
"is unwritable"))
2989 ((file-exists-p res
)
2990 (setq prompt
"exists")
2991 (not (y-or-n-p (format "File `%s' exists; overwrite? "
2994 (setq res
(read-file-name
2995 (format "File %s; save PostScript to file: " prompt
)
2996 (file-name-directory res
) nil nil
2997 (file-name-nondirectory res
))))
2998 (if (file-directory-p res
)
2999 (expand-file-name name
(file-name-as-directory res
))
3002 ;; The following functions implement a simple list-buffering scheme so
3003 ;; that ps-print doesn't have to repeatedly switch between buffers
3004 ;; while spooling. The functions `ps-output' and `ps-output-string' build
3005 ;; up the lists; the function `ps-flush-output' takes the lists and
3006 ;; insert its contents into the spool buffer (*PostScript*).
3008 (defvar ps-string-escape-codes
3009 (let ((table (make-vector 256 nil
))
3011 ;; control characters
3012 (while (<= char ?
\037)
3013 (aset table char
(format "\\%03o" char
))
3014 (setq char
(1+ char
)))
3015 ;; printable characters
3016 (while (< char ?
\177)
3017 (aset table char
(format "%c" char
))
3018 (setq char
(1+ char
)))
3019 ;; DEL and 8-bit characters
3020 (while (<= char ?
\377)
3021 (aset table char
(format "\\%o" char
))
3022 (setq char
(1+ char
)))
3023 ;; Override ASCII formatting characters with named escape code:
3024 (aset table ?
\n "\\n") ; [NL] linefeed
3025 (aset table ?
\r "\\r") ; [CR] carriage return
3026 (aset table ?
\t "\\t") ; [HT] horizontal tab
3027 (aset table ?
\b "\\b") ; [BS] backspace
3028 (aset table ?
\f "\\f") ; [NP] form feed
3029 ;; Escape PostScript escape and string delimiter characters:
3030 (aset table ?
\\ "\\\\")
3031 (aset table ?\
( "\\(")
3032 (aset table ?\
) "\\)")
3034 "Vector used to map characters to PostScript string escape codes.")
3036 (defun ps-output-string-prim (string)
3037 (insert "(") ;insert start-string delimiter
3038 (save-excursion ;insert string
3039 (insert (string-as-unibyte string
)))
3040 ;; Find and quote special characters as necessary for PS
3041 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
3042 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
3043 (let ((special (following-char)))
3045 (insert (aref ps-string-escape-codes special
))))
3046 (goto-char (point-max))
3047 (insert ")")) ;insert end-string delimiter
3049 (defun ps-init-output-queue ()
3050 (setq ps-output-head
'("")
3051 ps-output-tail ps-output-head
))
3053 (defun ps-output (&rest args
)
3054 (setcdr ps-output-tail args
)
3055 (while (cdr ps-output-tail
)
3056 (setq ps-output-tail
(cdr ps-output-tail
))))
3058 (defun ps-output-string (string)
3059 (ps-output t string
))
3061 (defun ps-output-list (the-list)
3062 (mapcar 'ps-output the-list
))
3064 ;; Output strings in the list ARGS in the PostScript prologue part.
3065 (defun ps-output-prologue (args)
3066 (ps-output 'prologue
(if (stringp args
) (list args
) args
)))
3068 (defun ps-flush-output ()
3070 (set-buffer ps-spool-buffer
)
3071 (goto-char (point-max))
3072 (while ps-output-head
3073 (let ((it (car ps-output-head
)))
3076 (setq ps-output-head
(cdr ps-output-head
))
3077 (ps-output-string-prim (car ps-output-head
)))
3079 (setq ps-output-head
(cdr ps-output-head
))
3081 (search-backward "\nBeginDoc")
3083 (apply 'insert
(car ps-output-head
))))
3086 (setq ps-output-head
(cdr ps-output-head
))))
3087 (ps-init-output-queue))
3089 (defun ps-insert-file (fname)
3092 (set-buffer ps-spool-buffer
)
3093 (goto-char (point-max))
3094 (insert-file fname
)))
3096 ;; These functions insert the arrays that define the contents of the
3099 (defun ps-generate-header-line (fonttag &optional content
)
3100 (ps-output " [ " fonttag
" ")
3102 ;; Literal strings should be output as is -- the string must
3103 ;; contain its own PS string delimiters, '(' and ')', if necessary.
3105 (ps-output content
))
3107 ;; Functions are called -- they should return strings; they will be
3108 ;; inserted as strings and the PS string delimiters added.
3109 ((and (symbolp content
) (fboundp content
))
3110 (ps-output-string (funcall content
)))
3112 ;; Variables will have their contents inserted. They should
3113 ;; contain strings, and will be inserted as strings.
3114 ((and (symbolp content
) (boundp content
))
3115 (ps-output-string (symbol-value content
)))
3117 ;; Anything else will get turned into an empty string.
3119 (ps-output-string "")))
3122 (defun ps-generate-header (name contents
)
3123 (ps-output "/" name
" [\n")
3124 (if (> ps-header-lines
0)
3126 (ps-generate-header-line "/h0" (car contents
))
3127 (while (and (< count ps-header-lines
)
3128 (setq contents
(cdr contents
)))
3129 (ps-generate-header-line "/h1" (car contents
))
3130 (setq count
(1+ count
)))
3131 (ps-output "] def\n"))))
3134 (defun ps-output-boolean (name bool
)
3135 (ps-output (format "/%s %s def\n" name
(if bool
"true" "false"))))
3138 (defun ps-background-pages (page-list func
)
3142 (let ((start (if (consp pages
) (car pages
) pages
))
3143 (end (if (consp pages
) (cdr pages
) pages
)))
3144 (and (integerp start
) (integerp end
) (<= start end
)
3145 (add-to-list 'ps-background-pages
(vector start end func
)))))
3147 (setq ps-background-all-pages
(cons func ps-background-all-pages
))))
3150 (defconst ps-boundingbox-re
3152 \\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3155 (defun ps-get-boundingbox ()
3157 (set-buffer ps-spool-buffer
)
3159 (if (re-search-forward ps-boundingbox-re nil t
)
3160 (vector (string-to-number ; lower x
3161 (buffer-substring (match-beginning 1) (match-end 1)))
3162 (string-to-number ; lower y
3163 (buffer-substring (match-beginning 2) (match-end 2)))
3164 (string-to-number ; upper x
3165 (buffer-substring (match-beginning 3) (match-end 3)))
3166 (string-to-number ; upper y
3167 (buffer-substring (match-beginning 4) (match-end 4))))
3168 (vector 0 0 0 0)))))
3171 ;; Emacs understands the %f format; we'll use it to limit color RGB values
3172 ;; to three decimals to cut down some on the size of the PostScript output.
3173 ;; Lucid emacsen will have to make do with %s (princ) for floats.
3175 (defvar ps-float-format
(if (eq ps-print-emacs-type
'emacs
)
3177 "%s ")) ; Lucid emacsen
3180 (defun ps-float-format (value &optional default
)
3181 (let ((literal (or value default
)))
3183 (format (if (numberp literal
)
3190 (defun ps-background-text ()
3193 (setq ps-background-text-count
(1+ ps-background-text-count
))
3194 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count
))
3195 (ps-output-string (nth 0 text
)) ; text
3198 (ps-float-format (nth 4 text
) 200.0) ; font size
3199 (format "/%s " (or (nth 3 text
) "Times-Roman")) ; font name
3200 (ps-float-format (nth 6 text
)
3201 "PrintHeight PrintPageWidth atan") ; rotation
3202 (ps-float-format (nth 5 text
) 0.85) ; gray
3203 (ps-float-format (nth 1 text
) "0") ; x position
3204 (ps-float-format (nth 2 text
) "BottomMargin") ; y position
3205 "\nShowBackText} def\n")
3206 (ps-background-pages (nthcdr 7 text
) ; page list
3207 (format "ShowBackText-%d\n"
3208 ps-background-text-count
)))
3209 ps-print-background-text
))
3212 (defun ps-background-image ()
3215 (let ((image-file (expand-file-name (nth 0 image
))))
3216 (when (file-readable-p image-file
)
3217 (setq ps-background-image-count
(1+ ps-background-image-count
))
3219 (format "/ShowBackImage-%d {\n--back-- "
3220 ps-background-image-count
)
3221 (ps-float-format (nth 5 image
) 0.0) ; rotation
3222 (ps-float-format (nth 3 image
) 1.0) ; x scale
3223 (ps-float-format (nth 4 image
) 1.0) ; y scale
3224 (ps-float-format (nth 1 image
) ; x position
3225 "PrintPageWidth 2 div")
3226 (ps-float-format (nth 2 image
) ; y position
3227 "PrintHeight 2 div BottomMargin add")
3228 "\nBeginBackImage\n")
3229 (ps-insert-file image-file
)
3230 ;; coordinate adjustment to centralize image
3231 ;; around x and y position
3232 (let ((box (ps-get-boundingbox)))
3234 (set-buffer ps-spool-buffer
)
3236 (if (re-search-backward "^--back--" nil t
)
3240 (- (+ (/ (- (aref box
2) (aref box
0)) 2.0)
3243 (- (+ (/ (- (aref box
3) (aref box
1)) 2.0)
3246 (ps-output "\nEndBackImage} def\n")
3247 (ps-background-pages (nthcdr 6 image
) ; page list
3248 (format "ShowBackImage-%d\n"
3249 ps-background-image-count
)))))
3250 ps-print-background-image
))
3253 (defun ps-background (page-number)
3254 (let (has-local-background)
3255 (mapcar #'(lambda (range)
3256 (and (<= (aref range
0) page-number
)
3257 (<= page-number
(aref range
1))
3258 (if has-local-background
3259 (ps-output (aref range
2))
3260 (setq has-local-background t
)
3261 (ps-output "/printLocalBackground {\n"
3263 ps-background-pages
)
3264 (and has-local-background
(ps-output "} def\n"))))
3267 ;; Return a list of the distinct elements of LIST.
3268 ;; Elements are compared with `equal'.
3269 (defun ps-remove-duplicates (list)
3270 (let (new (tail list
))
3272 (or (member (car tail
) new
)
3273 (setq new
(cons (car tail
) new
)))
3274 (setq tail
(cdr tail
)))
3278 ;; Find the first occurrence of ITEM in LIST.
3279 ;; Return the index of the matching item, or nil if not found.
3280 ;; Elements are compared with `eq'.
3281 (defun ps-alist-position (item list
)
3282 (let ((tail list
) (index 0) found
)
3284 (if (setq found
(eq (car (car tail
)) item
))
3286 (setq index
(1+ index
)
3291 (defconst ps-n-up-database
3428 ;; Ledger paper size is a special case, it is the only paper size where the
3429 ;; normal size is landscaped, that is, the height is smaller than width.
3430 ;; So, we use the special value `pag' in the `landscape' field.
3574 "Alist which is the page matrix database used for N-up printing.
3576 Each element has the following form:
3579 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
3583 PAGE is the page size used (see `ps-paper-type').
3584 MAX is the maximum elements of this page matrix.
3585 LANDSCAPE specifies if page matrix is landscaped, has the following valid
3587 nil the sheet is in portrait mode.
3588 t the sheet is in landscape mode.
3589 pag the sheet is in portrait mode and page is in landscape mode.
3590 LINES is the number of lines of page matrix.
3591 COLUMNS is the number of columns of page matrix.
3592 COL-MISSING is the number of columns missing to fill the sheet.")
3595 (defmacro ps-n-up-landscape
(mat) `(nth 1 ,mat
))
3596 (defmacro ps-n-up-lines
(mat) `(nth 2 ,mat
))
3597 (defmacro ps-n-up-columns
(mat) `(nth 3 ,mat
))
3598 (defmacro ps-n-up-missing
(mat) `(nth 4 ,mat
))
3601 (defun ps-n-up-printing ()
3602 ;; force `ps-n-up-printing' be in range 1 to 100.
3603 (setq ps-n-up-printing
(max (min ps-n-up-printing
100) 1))
3604 ;; find suitable page matrix for a given `ps-paper-type'.
3605 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database
))))
3607 (while (> ps-n-up-printing
(caar the-list
))
3608 (setq the-list
(cdr the-list
))))
3612 (defconst ps-n-up-filling-database
3614 "PageWidth" ; N-Up-XColumn
3616 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3617 "LandscapePageHeight neg" ; N-Up-YLine
3618 "N-Up-Lines" ; N-Up-Repeat
3619 "N-Up-Columns" ; N-Up-End
3623 "PageWidth" ; N-Up-XColumn
3625 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3626 "LandscapePageHeight" ; N-Up-YLine
3627 "N-Up-Lines" ; N-Up-Repeat
3628 "N-Up-Columns" ; N-Up-End
3630 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3632 "PageWidth neg" ; N-Up-XColumn
3634 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3635 "LandscapePageHeight neg" ; N-Up-YLine
3636 "N-Up-Lines" ; N-Up-Repeat
3637 "N-Up-Columns" ; N-Up-End
3638 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3641 "PageWidth neg" ; N-Up-XColumn
3643 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3644 "LandscapePageHeight" ; N-Up-YLine
3645 "N-Up-Lines" ; N-Up-Repeat
3646 "N-Up-Columns" ; N-Up-End
3647 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3648 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3651 "LandscapePageHeight neg" ; N-Up-YColumn
3652 "PageWidth" ; N-Up-XLine
3653 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3654 "N-Up-Columns" ; N-Up-Repeat
3655 "N-Up-Lines" ; N-Up-End
3660 "LandscapePageHeight" ; N-Up-YColumn
3661 "PageWidth" ; N-Up-XLine
3662 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3663 "N-Up-Columns" ; N-Up-Repeat
3664 "N-Up-Lines" ; N-Up-End
3666 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3669 "LandscapePageHeight neg" ; N-Up-YColumn
3670 "PageWidth neg" ; N-Up-XLine
3671 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3672 "N-Up-Columns" ; N-Up-Repeat
3673 "N-Up-Lines" ; N-Up-End
3674 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3678 "LandscapePageHeight" ; N-Up-YColumn
3679 "PageWidth neg" ; N-Up-XLine
3680 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3681 "N-Up-Columns" ; N-Up-Repeat
3682 "N-Up-Lines" ; N-Up-End
3683 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3684 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
3685 "Alist for n-up printing initializations.
3687 Each element has the following form:
3689 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
3692 KIND is a valid value of `ps-n-up-filling'.
3693 XCOL YCOL are the relative position for the next column.
3694 XLIN YLIN are the relative position for the beginning of next line.
3695 REPEAT is the number of repetions for external loop.
3696 END is the number of repetions for internal loop and also the number of pages in
3698 XSTART YSTART are the relative position for the first page in a sheet.")
3701 (defun ps-n-up-filling ()
3702 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database
)
3703 (assq 'left-top ps-n-up-filling-database
))))
3706 (defmacro ps-n-up-xcolumn
(init) `(nth 0 ,init
))
3707 (defmacro ps-n-up-ycolumn
(init) `(nth 1 ,init
))
3708 (defmacro ps-n-up-xline
(init) `(nth 2 ,init
))
3709 (defmacro ps-n-up-yline
(init) `(nth 3 ,init
))
3710 (defmacro ps-n-up-repeat
(init) `(nth 4 ,init
))
3711 (defmacro ps-n-up-end
(init) `(nth 5 ,init
))
3712 (defmacro ps-n-up-xstart
(init) `(nth 6 ,init
))
3713 (defmacro ps-n-up-ystart
(init) `(nth 7 ,init
))
3716 (defconst ps-error-handler-alist
3720 (paper-and-system .
3))
3721 "Alist for error handler message")
3724 (defun ps-begin-file ()
3725 (ps-get-page-dimensions)
3726 (setq ps-page-postscript
0
3728 ps-background-text-count
0
3729 ps-background-image-count
0
3730 ps-background-pages nil
3731 ps-background-all-pages nil
)
3733 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
3734 (tumble (if ps-landscape-mode
(not ps-spool-tumble
) ps-spool-tumble
))
3735 (n-up (ps-n-up-printing))
3736 (n-up-filling (ps-n-up-filling)))
3737 (and (> ps-n-up-printing
1) (setq tumble
(not tumble
)))
3740 "%%Title: " (buffer-name) ; Take job name from name of
3741 ; first buffer printed
3742 "\n%%Creator: " (user-full-name)
3743 " (using ps-print v" ps-print-version
3744 ")\n%%CreationDate: "
3745 (time-stamp-hh:mm
:ss
) " " (time-stamp-mon-dd-yyyy)
3747 (if ps-landscape-mode
"Landscape" "Portrait")
3748 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
3749 (mapconcat 'identity
3750 (ps-remove-duplicates
3751 (append (ps-fonts 'ps-font-for-text
)
3752 (list (ps-font 'ps-font-for-header
'normal
)
3753 (ps-font 'ps-font-for-header
'bold
))))
3755 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions
)
3756 (format " %d" (round (ps-page-dimensions-get-width dimensions
)))
3757 (format " %d" (round (ps-page-dimensions-get-height dimensions
)))
3758 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
3760 (format " duplex%s" (if tumble
"(tumble)\n" "\n"))
3763 (ps-insert-string ps-print-prologue-header
)
3765 (ps-output "%%EndComments\n\n%%BeginPrologue\n\n"
3766 "/languagelevel where{pop}{/languagelevel 1 def}ifelse\n"
3767 (format "/ErrorMessage %s def\n\n"
3768 (or (cdr (assoc ps-error-handler-message
3769 ps-error-handler-alist
))
3772 "\n%%BeginProcSet: UserDefinedPrologue\n\n")
3774 (ps-insert-string ps-user-defined-prologue
)
3776 (ps-output "\n%%EndProcSet\n\n")
3778 (ps-output-boolean "LandscapeMode "
3779 (or ps-landscape-mode
3780 (eq (ps-n-up-landscape n-up
) 'pag
)))
3781 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns
)
3783 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height
)
3784 (format "/PrintPageWidth %s def\n"
3785 (- (* (+ ps-print-width ps-inter-column
)
3786 ps-number-of-columns
)
3788 (format "/PrintWidth %s def\n" ps-print-width
)
3789 (format "/PrintHeight %s def\n" ps-print-height
)
3791 (format "/LeftMargin %s def\n" ps-left-margin
)
3792 (format "/RightMargin %s def\n" ps-right-margin
)
3793 (format "/InterColumn %s def\n" ps-inter-column
)
3795 (format "/BottomMargin %s def\n" ps-bottom-margin
)
3796 (format "/TopMargin %s def\n" ps-top-margin
) ; not used
3797 (format "/HeaderOffset %s def\n" ps-header-offset
)
3798 (format "/HeaderPad %s def\n" ps-header-pad
))
3800 (ps-output-boolean "PrintHeader " ps-print-header
)
3801 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header
)
3802 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame
)
3803 (ps-output-boolean "ShowNofN " ps-show-n-of-n
)
3804 (ps-output-boolean "DuplexValue " ps-spool-duplex
)
3805 (ps-output-boolean "TumbleValue " tumble
)
3807 (let ((line-height (ps-line-height 'ps-font-for-text
)))
3808 (ps-output (format "/LineHeight %s def\n" line-height
)
3809 (format "/LinesPerColumn %d def\n"
3810 (round (/ (+ ps-print-height
3811 (* line-height
0.45))
3814 (ps-output-boolean "Zebra " ps-zebra-stripes
)
3815 (ps-output-boolean "PrintLineNumber " ps-line-number
)
3816 (ps-output (format "/ZebraHeight %d def\n" ps-zebra-stripe-height
)
3818 (ps-format-color ps-zebra-color
0.95)
3819 "def\n/BackgroundColor "
3820 (ps-format-color ps-default-bg
1.0)
3821 "def\n/UseSetpagedevice "
3822 (if (eq ps-spool-config
'setpagedevice
)
3823 "/setpagedevice where{pop languagelevel 2 eq}{false}ifelse"
3825 " def\n\n/PageWidth "
3826 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
3827 (format "/N-Up %d def\n" ps-n-up-printing
))
3828 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up
) t
))
3829 (ps-output-boolean "N-Up-Border " ps-n-up-border-p
)
3830 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up
))
3831 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up
))
3832 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up
))
3833 (format "/N-Up-Margin %s def\n" ps-n-up-margin
)
3835 (if ps-landscape-mode
3836 (ps-n-up-end n-up-filling
)
3837 (ps-n-up-repeat n-up-filling
))
3839 (if ps-landscape-mode
3840 (ps-n-up-repeat n-up-filling
)
3841 (ps-n-up-end n-up-filling
))
3842 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling
)
3843 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling
)
3844 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling
)
3845 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling
)
3846 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling
)
3847 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling
) " def\n")
3849 (ps-background-text)
3850 (ps-background-image)
3851 (setq ps-background-all-pages
(nreverse ps-background-all-pages
)
3852 ps-background-pages
(nreverse ps-background-pages
))
3854 (ps-output "\n" ps-print-prologue-1
)
3856 (ps-output "\n/printGlobalBackground {\n")
3857 (ps-output-list ps-background-all-pages
)
3858 (ps-output "} def\n/printLocalBackground {\n} def\n")
3861 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
3862 ps-header-title-font-size-internal
3863 (ps-font 'ps-font-for-header
'bold
))
3864 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
3865 ps-header-font-size-internal
3866 (ps-font 'ps-font-for-header
'normal
)))
3868 (ps-output "\n" ps-print-prologue-2
"\n")
3871 (let ((font (ps-font-alist 'ps-font-for-text
))
3874 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
3876 ps-font-size-internal
3877 (ps-font 'ps-font-for-text
(car (car font
)))))
3878 (setq font
(cdr font
)
3881 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database
))))
3882 (ps-output (format "/SpaceWidthRatio %f def\n"
3883 (/ (ps-lookup 'space-width
) (ps-lookup 'size
)))))
3885 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
3886 (unless (eq ps-spool-config
'lpr-switches
)
3887 (ps-output "\n%%BeginFeature: *Duplex "
3888 (ps-boolean-capitalized ps-spool-duplex
)
3890 (ps-boolean-capitalized tumble
)
3892 ps-print-duplex-feature
3893 "\n%%EndFeature\n")))
3894 (ps-output "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n")
3895 (and ps-banner-page-when-duplexing
3896 (ps-output "\n%%Page: 0 0\nsave showpage restore\n")))
3899 (defun ps-format-color (color &optional default
)
3900 (let ((the-color (if (stringp color
)
3901 (ps-color-scale color
)
3903 (if (and the-color
(listp the-color
))
3905 (format ps-color-format
3910 (ps-float-format (if (numberp the-color
) the-color default
)))))
3913 (defun ps-insert-string (prologue)
3914 (let ((str (if (functionp prologue
)
3921 (defun ps-boolean-capitalized (bool)
3922 (if bool
"True" "False"))
3925 (defun ps-header-dirpart ()
3926 (let ((fname (buffer-file-name)))
3928 (if (string-equal (buffer-name) (file-name-nondirectory fname
))
3929 (abbreviate-file-name (file-name-directory fname
))
3934 (defun ps-get-buffer-name ()
3936 ;; Indulge Jim this little easter egg:
3937 ((string= (buffer-name) "ps-print.el")
3938 "Hey, Cool! It's ps-print.el!!!")
3939 ;; Indulge Jack this other little easter egg:
3940 ((string= (buffer-name) "sokoban.el")
3941 "Super! C'est sokoban.el!")
3943 (and ps-printing-region-p
"Subset of: ")
3945 (and (buffer-modified-p) " (unsaved)")))))
3948 (defun ps-get-font-size (font-sym)
3949 (let ((font-size (symbol-value font-sym
)))
3950 (cond ((numberp font-size
)
3952 ((and (consp font-size
)
3953 (numberp (car font-size
))
3954 (numberp (cdr font-size
)))
3955 (if ps-landscape-mode
3959 (error "Invalid font size `%S' for `%S'" font-size font-sym
)))))
3962 (defun ps-begin-job ()
3963 (or (equal ps-mark-code-directory ps-postscript-code-directory
)
3964 (setq ps-print-prologue-0
(ps-prologue-file 0)
3965 ps-print-prologue-1
(ps-prologue-file 1)
3966 ps-print-prologue-2
(ps-prologue-file 2)
3967 ps-print-duplex-feature
(ps-prologue-file 3)
3968 ps-mark-code-directory ps-postscript-code-directory
))
3970 (set-buffer ps-spool-buffer
)
3971 (goto-char (point-max))
3972 (and (re-search-backward "^%%Trailer$" nil t
)
3973 (delete-region (match-beginning 0) (point-max))))
3974 (setq ps-showline-count
(car ps-printing-region
)
3976 ps-font-size-internal
(ps-get-font-size 'ps-font-size
)
3977 ps-header-font-size-internal
(ps-get-font-size 'ps-header-font-size
)
3978 ps-header-title-font-size-internal
3979 (ps-get-font-size 'ps-header-title-font-size
)
3980 ps-control-or-escape-regexp
3981 (cond ((eq ps-print-control-characters
'8-bit
)
3982 (string-as-unibyte "[\000-\037\177-\377]"))
3983 ((eq ps-print-control-characters
'control-8-bit
)
3984 (string-as-unibyte "[\000-\037\177-\237]"))
3985 ((eq ps-print-control-characters
'control
)
3988 ps-default-foreground
(ps-rgb-color ps-default-fg
0.0)
3989 ps-default-color
(and ps-print-color-p ps-default-foreground
)
3990 ps-current-color ps-default-color
3991 ;; Set the color scale. We do it here instead of in the defvar so
3992 ;; that ps-print can be dumped into emacs. This expression can't be
3993 ;; evaluated at dump-time because X isn't initialized.
3994 ps-color-p
(and ps-print-color-p
(ps-color-device))
3995 ps-print-color-scale
(if ps-color-p
3996 (float (car (ps-color-values "white")))
4000 (defun ps-rgb-color (color default
)
4001 (cond ((and color
(listp color
)) color
)
4002 ((stringp color
) (ps-color-scale color
))
4003 ((numberp color
) (list color color color
))
4004 (t (list default default default
))
4008 (defmacro ps-page-number
()
4009 `(1+ (/ (1- ps-page-count
) ps-number-of-columns
)))
4011 (defun ps-end-file (needs-begin-file)
4013 ;; Back to the PS output buffer to set the last page n-up printing
4015 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing
))
4017 (set-buffer ps-spool-buffer
)
4018 (goto-char (point-max))
4019 (and (> pages-per-sheet
0)
4020 (re-search-backward "^[0-9]+ BeginSheet$" nil t
)
4021 (replace-match (format "%d BeginSheet" pages-per-sheet
) t
))))
4023 (and ps-spool-duplex
(= (mod ps-page-order
2) 1)
4025 ;; Set end of PostScript file
4026 (ps-output "EndSheet\n\n%%Trailer\n%%Pages: "
4028 (if (and needs-begin-file ps-banner-page-when-duplexing
)
4031 "\n\nEndDoc\n\n%%EOF\n"))
4034 (defun ps-next-page ()
4040 (defun ps-header-sheet ()
4041 ;; Print only when a new sheet begins.
4042 (setq ps-page-postscript
(1+ ps-page-postscript
)
4043 ps-page-order
(1+ ps-page-order
))
4044 (and (> ps-page-order
1)
4045 (ps-output "EndSheet\n"))
4046 (ps-output (format "\n%%%%Page: %d %d\n"
4047 ps-page-postscript ps-page-order
))
4048 (ps-output (format "%d BeginSheet\nBeginDSCPage\n" ps-n-up-printing
)))
4051 (defsubst ps-header-page
()
4052 ;; set total line and page number when printing has finished
4053 ;; (see `ps-generate')
4056 (zerop (mod ps-page-count ps-number-of-columns
))
4057 (setq ps-page-count
(1+ ps-page-count
)))
4059 (if (zerop (mod ps-page-postscript ps-n-up-printing
))
4060 ;; Print only when a new sheet begins.
4063 'ps-print-begin-sheet-hook
)
4064 ;; Print only when a new page begins.
4065 (setq ps-page-postscript
(1+ ps-page-postscript
))
4066 (ps-output "BeginDSCPage\n")
4067 'ps-print-begin-page-hook
)
4068 (ps-background ps-page-postscript
))
4069 ;; Print only when a new column begins.
4070 (ps-output "BeginDSCPage\n")
4071 'ps-print-begin-column-hook
)))
4073 (defun ps-begin-page ()
4074 (ps-get-page-dimensions)
4075 (setq ps-width-remaining ps-print-width
4076 ps-height-remaining ps-print-height
)
4080 (ps-output (format "/LineNumber %d def\n" ps-showline-count
)
4081 (format "/PageNumber %d def\n" (if ps-print-only-one-header
4085 (when ps-print-header
4086 (ps-generate-header "HeaderLinesLeft" ps-left-header
)
4087 (ps-generate-header "HeaderLinesRight" ps-right-header
)
4088 (ps-output (format "%d SetHeaderLines\n" ps-header-lines
)))
4090 (ps-output "BeginPage\n")
4091 (ps-set-font ps-current-font
)
4092 (ps-set-bg ps-current-bg
)
4093 (ps-set-color ps-current-color
)
4094 (ps-mule-begin-page))
4096 (defun ps-end-page ()
4097 (ps-output "EndPage\nEndDSCPage\n"))
4099 (defun ps-dummy-page ()
4100 (let ((ps-n-up-printing 0))
4102 (ps-output "/PrintHeader false def
4104 /PrintLineNumber false def
4108 (setq ps-page-postscript ps-n-up-printing
))
4110 (defun ps-next-line ()
4111 (setq ps-showline-count
(1+ ps-showline-count
))
4112 (let ((lh (ps-line-height 'ps-font-for-text
)))
4113 (if (< ps-height-remaining lh
)
4115 (setq ps-width-remaining ps-print-width
4116 ps-height-remaining
(- ps-height-remaining lh
))
4117 (ps-output "HL\n"))))
4119 (defun ps-continue-line ()
4120 (let ((lh (ps-line-height 'ps-font-for-text
)))
4121 (if (< ps-height-remaining lh
)
4123 (setq ps-width-remaining ps-print-width
4124 ps-height-remaining
(- ps-height-remaining lh
))
4125 (ps-output "SL\n"))))
4127 (defun ps-find-wrappoint (from to char-width
)
4128 (let ((avail (truncate (/ ps-width-remaining char-width
)))
4131 (cons to
(* todo char-width
))
4132 (cons (+ from avail
) ps-width-remaining
))))
4134 (defun ps-basic-plot-string (from to
&optional bg-color
)
4135 (let* ((wrappoint (ps-find-wrappoint from to
4136 (ps-avg-char-width 'ps-font-for-text
)))
4137 (to (car wrappoint
))
4138 (string (buffer-substring-no-properties from to
)))
4139 (ps-mule-prepare-ascii-font string
)
4140 (ps-output-string string
)
4144 (defun ps-basic-plot-whitespace (from to
&optional bg-color
)
4145 (let* ((wrappoint (ps-find-wrappoint from to
4146 (ps-space-width 'ps-font-for-text
)))
4147 (to (car wrappoint
)))
4148 (ps-output (format "%d W\n" (- to from
)))
4151 (defun ps-plot (plotfunc from to
&optional bg-color
)
4153 (let* ((wrappoint (funcall plotfunc from to bg-color
))
4154 (plotted-to (car wrappoint
))
4155 (plotted-width (cdr wrappoint
)))
4156 (setq from plotted-to
4157 ps-width-remaining
(- ps-width-remaining plotted-width
))
4159 (ps-continue-line))))
4160 (if ps-razzle-dazzle
4161 (let* ((q-todo (- (point-max) (point-min)))
4162 (q-done (- (point) (point-min)))
4163 (chunkfrac (/ q-todo
8))
4164 (chunksize (min chunkfrac
1000)))
4165 (if (> (- q-done ps-razchunk
) chunksize
)
4167 (setq ps-razchunk q-done
)
4168 (message "Formatting...%3d%%"
4170 (/ (* 100 q-done
) q-todo
)
4171 (/ q-done
(/ q-todo
100)))
4174 (defvar ps-last-font nil
)
4176 (defun ps-set-font (font)
4177 (setq ps-last-font
(format "f%d" (setq ps-current-font font
)))
4178 (ps-output (format "/%s F\n" ps-last-font
)))
4180 (defun ps-set-bg (color)
4181 (if (setq ps-current-bg color
)
4182 (ps-output (format ps-color-format
4183 (nth 0 color
) (nth 1 color
) (nth 2 color
))
4185 (ps-output "false BG\n")))
4187 (defun ps-set-color (color)
4188 (setq ps-current-color
(or color ps-default-foreground
))
4189 (ps-output (format ps-color-format
4190 (nth 0 ps-current-color
)
4191 (nth 1 ps-current-color
) (nth 2 ps-current-color
))
4195 (defvar ps-current-effect
0)
4198 (defun ps-plot-region (from to font
&optional fg-color bg-color effects
)
4199 (if (not (equal font ps-current-font
))
4202 ;; Specify a foreground color only if one's specified and it's
4203 ;; different than the current.
4204 (if (not (equal fg-color ps-current-color
))
4205 (ps-set-color fg-color
))
4207 (if (not (equal bg-color ps-current-bg
))
4208 (ps-set-bg bg-color
))
4210 ;; Specify effects (underline, overline, box, etc)
4212 ((not (integerp effects
))
4213 (ps-output "0 EF\n")
4214 (setq ps-current-effect
0))
4215 ((/= effects ps-current-effect
)
4216 (ps-output (number-to-string effects
) " EF\n")
4217 (setq ps-current-effect effects
)))
4219 ;; Starting at the beginning of the specified region...
4223 ;; ...break the region up into chunks separated by tabs, linefeeds,
4224 ;; pagefeeds, control characters, and plot each chunk.
4226 (if (re-search-forward ps-control-or-escape-regexp to t
)
4227 ;; region with some control characters or some multi-byte characters
4228 (let* ((match-point (match-beginning 0))
4229 (match (char-after match-point
))
4230 (composition (find-composition from
(1+ match-point
))))
4232 (if (and (nth 2 composition
)
4233 (<= (car composition
) match-point
))
4235 (setq match-point
(car composition
)
4237 (goto-char (nth 1 composition
)))
4238 (setq composition nil
)))
4239 (when (< from match-point
)
4240 (ps-mule-set-ascii-font)
4241 (ps-plot 'ps-basic-plot-string from match-point bg-color
))
4243 ((= match ?
\t) ; tab
4244 (let ((linestart (line-beginning-position)))
4246 (setq from
(+ linestart
(current-column)))
4247 (when (re-search-forward "[ \t]+" to t
)
4248 (ps-mule-set-ascii-font)
4249 (ps-plot 'ps-basic-plot-whitespace
4250 from
(+ linestart
(current-column))
4253 ((= match ?
\n) ; newline
4256 ((= match ?
\f) ; form feed
4257 ;; do not skip page if previous character is NEWLINE and
4258 ;; it is a beginning of page.
4259 (or (and (= (char-after (1- match-point
)) ?
\n)
4260 (= ps-height-remaining ps-print-height
))
4263 (composition ; a composite sequence
4264 (ps-plot 'ps-mule-plot-composition match-point
(point) bg-color
))
4266 ; characters from ^@ to ^_ and
4267 ((> match
255) ; a multi-byte character
4268 (let* ((charset (char-charset match
))
4269 (composition (find-composition match-point to
))
4270 (stop (if (nth 2 composition
) (car composition
) to
)))
4271 (or (eq charset
'composition
)
4272 (while (and (< (point) stop
) (eq (charset-after) charset
))
4274 (ps-plot 'ps-mule-plot-string match-point
(point) bg-color
)))
4276 (t ; characters from 127 to 255
4277 (ps-control-character match
)))
4278 (setq from
(point)))
4279 ;; region without control characters nor multi-byte characters
4280 (ps-mule-set-ascii-font)
4281 (ps-plot 'ps-basic-plot-string from to bg-color
)
4284 (defvar ps-string-control-codes
4285 (let ((table (make-vector 256 nil
))
4287 ;; control character
4288 (while (<= char ?
\037)
4289 (aset table char
(format "^%c" (+ char ?
@)))
4290 (setq char
(1+ char
)))
4291 ;; printable character
4292 (while (< char ?
\177)
4293 (aset table char
(format "%c" char
))
4294 (setq char
(1+ char
)))
4296 (aset table char
"^?")
4298 (while (<= (setq char
(1+ char
)) ?
\377)
4299 (aset table char
(format "\\%o" char
)))
4301 "Vector used to map characters to a printable string.")
4303 (defun ps-control-character (char)
4304 (let* ((str (aref ps-string-control-codes char
))
4308 (char-width (ps-avg-char-width 'ps-font-for-text
))
4309 (wrappoint (ps-find-wrappoint from to char-width
)))
4310 (if (< (car wrappoint
) to
)
4312 (setq ps-width-remaining
(- ps-width-remaining
(* len char-width
)))
4313 (ps-mule-prepare-ascii-font str
)
4314 (ps-output-string str
)
4315 (ps-output " S\n")))
4317 (defun ps-color-scale (color)
4318 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
4319 (mapcar #'(lambda (value) (/ value ps-print-color-scale
))
4320 (ps-color-values color
)))
4323 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4325 (defun ps-color-values (x-color)
4326 (if (fboundp 'x-color-values
)
4327 (x-color-values x-color
)
4328 (error "No available function to determine X color values.")))
4333 (defun ps-color-values (x-color)
4334 (let ((the-color (if (color-specifier-p x-color
)
4335 (color-name x-color
)
4338 ((fboundp 'x-color-values
)
4339 (x-color-values the-color
))
4340 ((and (fboundp 'color-instance-rgb-components
)
4342 (color-instance-rgb-components
4343 (if (color-instance-p x-color
)
4345 (make-color-instance the-color
))))
4347 (error "No available function to determine X color values.")))))
4351 (defun ps-face-attributes (face)
4352 "Return face attribute vector.
4354 If FACE is not in `ps-print-face-extension-alist' or in
4355 `ps-print-face-alist', insert it on `ps-print-face-alist' and
4356 return the attribute vector.
4358 If FACE is not a valid face name, it is used default face."
4359 (cdr (or (assq face ps-print-face-extension-alist
)
4360 (assq face ps-print-face-alist
)
4361 (let* ((the-face (if (facep face
) face
'default
))
4362 (new-face (ps-screen-to-bit-face the-face
)))
4363 (or (and (eq the-face
'default
)
4364 (assq the-face ps-print-face-alist
))
4365 (setq ps-print-face-alist
(cons new-face ps-print-face-alist
)))
4369 (defun ps-face-attribute-list (face-or-list)
4370 (if (listp face-or-list
)
4373 foreground background face-attr
)
4375 (setq face-attr
(ps-face-attributes (car face-or-list
))
4376 effects
(logior effects
(aref face-attr
0)))
4377 (or foreground
(setq foreground
(aref face-attr
1)))
4378 (or background
(setq background
(aref face-attr
2)))
4379 (setq face-or-list
(cdr face-or-list
)))
4380 (vector effects foreground background
))
4382 (ps-face-attributes face-or-list
)))
4385 (defconst ps-font-type
(vector nil
'bold
'italic
'bold-italic
))
4388 (defun ps-plot-with-face (from to face
)
4390 ((null face
) ; print text with null face
4391 (ps-plot-region from to
0))
4392 ((eq face
'emacs--invisible--face
)) ; skip invisible text!!!
4393 (t ; otherwise, text has a valid face
4394 (let* ((face-bit (ps-face-attribute-list face
))
4395 (effect (aref face-bit
0))
4396 (foreground (aref face-bit
1))
4397 (background (aref face-bit
2))
4398 (fg-color (if (and ps-color-p foreground
)
4399 (ps-color-scale foreground
)
4401 (bg-color (and ps-color-p background
4402 (ps-color-scale background
))))
4405 (ps-font-number 'ps-font-for-text
4406 (or (aref ps-font-type
(logand effect
3))
4408 fg-color bg-color
(lsh effect -
2)))))
4412 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list
)
4413 (let* ((frame-font (or (face-font-instance face
)
4414 (face-font-instance 'default
)))
4415 (kind-cons (and frame-font
4417 (font-instance-properties frame-font
))))
4418 (kind-spec (cdr-safe kind-cons
))
4419 (case-fold-search t
))
4420 (or (and kind-spec
(string-match kind-regex kind-spec
))
4421 ;; Kludge-compatible:
4422 (memq face kind-list
))))
4425 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4427 (defun ps-face-bold-p (face)
4428 (or (face-bold-p face
)
4429 (memq face ps-bold-faces
)))
4431 (defun ps-face-italic-p (face)
4432 (or (face-italic-p face
)
4433 (memq face ps-italic-faces
)))
4438 (defun ps-face-bold-p (face)
4439 (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold"
4442 (defun ps-face-italic-p (face)
4443 (or (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o" ps-italic-faces
)
4444 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o" ps-italic-faces
)))
4448 (defun ps-face-underlined-p (face)
4449 (or (face-underline-p face
)
4450 (memq face ps-underlined-faces
)))
4453 ;; Ensure that face-list is fbound.
4454 (or (fboundp 'face-list
) (defalias 'face-list
'list-faces
))
4457 (defun ps-build-reference-face-lists ()
4458 ;; Ensure that face database is updated with faces on
4459 ;; `font-lock-face-attributes' (obsolete stuff)
4460 (ps-font-lock-face-attributes)
4461 ;; Now, rebuild reference face lists
4462 (setq ps-print-face-alist nil
)
4463 (if ps-auto-font-detect
4464 (mapcar 'ps-map-face
(face-list))
4465 (mapcar 'ps-set-face-bold ps-bold-faces
)
4466 (mapcar 'ps-set-face-italic ps-italic-faces
)
4467 (mapcar 'ps-set-face-underline ps-underlined-faces
))
4468 (setq ps-build-face-reference nil
))
4471 (defun ps-set-face-bold (face)
4472 (ps-set-face-attribute face
1))
4474 (defun ps-set-face-italic (face)
4475 (ps-set-face-attribute face
2))
4477 (defun ps-set-face-underline (face)
4478 (ps-set-face-attribute face
4))
4481 (defun ps-set-face-attribute (face effect
)
4482 (let ((face-bit (cdr (ps-map-face face
))))
4483 (aset face-bit
0 (logior (aref face-bit
0) effect
))))
4486 (defun ps-map-face (face)
4487 (let* ((face-map (ps-screen-to-bit-face face
))
4488 (ps-face-bit (cdr (assq (car face-map
) ps-print-face-alist
))))
4490 ;; if face exists, merge both
4491 (let ((face-bit (cdr face-map
)))
4492 (aset ps-face-bit
0 (logior (aref ps-face-bit
0) (aref face-bit
0)))
4493 (or (aref ps-face-bit
1) (aset ps-face-bit
1 (aref face-bit
1)))
4494 (or (aref ps-face-bit
2) (aset ps-face-bit
2 (aref face-bit
2))))
4495 ;; if face does not exist, insert it
4496 (setq ps-print-face-alist
(cons face-map ps-print-face-alist
)))
4500 (defun ps-screen-to-bit-face (face)
4502 (vector (logior (if (ps-face-bold-p face
) 1 0) ; bold
4503 (if (ps-face-italic-p face
) 2 0) ; italic
4504 (if (ps-face-underlined-p face
) 4 0)) ; underline
4505 (face-foreground face
)
4506 (face-background face
))))
4509 (cond ((not (eq ps-print-emacs-type
'emacs
))
4513 (defun ps-mapper (extent list
)
4514 (nconc list
(list (list (extent-start-position extent
) 'push extent
)
4515 (list (extent-end-position extent
) 'pull extent
)))
4518 (defun ps-extent-sorter (a b
)
4519 (< (extent-priority a
) (extent-priority b
)))
4523 (defun ps-print-ensure-fontified (start end
)
4524 (and (boundp 'lazy-lock-mode
) (symbol-value 'lazy-lock-mode
)
4525 (lazy-lock-fontify-region start end
)))
4527 (defun ps-generate-postscript-with-faces (from to
)
4528 ;; Some initialization...
4529 (setq ps-current-effect
0)
4531 ;; Build the reference lists of faces if necessary.
4532 (if (or ps-always-build-face-reference
4533 ps-build-face-reference
)
4535 (message "Collecting face information...")
4536 (ps-build-reference-face-lists)))
4537 ;; Generate some PostScript.
4539 (narrow-to-region from to
)
4540 (ps-print-ensure-fontified from to
)
4541 (let ((face 'default
)
4544 ((or (eq ps-print-emacs-type
'lucid
)
4545 (eq ps-print-emacs-type
'xemacs
))
4546 ;; Build the list of extents...
4547 (let ((a (cons 'dummy nil
))
4548 record type extent extent-list
)
4549 (map-extents 'ps-mapper nil from to a
)
4550 (setq a
(sort (cdr a
) 'car-less-than-car
)
4553 ;; Loop through the extents...
4555 (setq record
(car a
)
4557 position
(car record
)
4563 extent
(car record
))
4565 ;; Plot up to this record.
4566 ;; XEmacs 19.12: for some reason, we're getting into a
4567 ;; situation in which some of the records have
4568 ;; positions less than 'from'. Since we've narrowed
4569 ;; the buffer, this'll generate errors. This is a
4570 ;; hack, but don't call ps-plot-with-face unless from >
4572 (and (>= from
(point-min)) (<= position
(point-max))
4573 (ps-plot-with-face from position face
))
4577 (and (extent-face extent
)
4578 (setq extent-list
(sort (cons extent extent-list
)
4579 'ps-extent-sorter
))))
4582 (setq extent-list
(sort (delq extent extent-list
)
4583 'ps-extent-sorter
))))
4585 (setq face
(if extent-list
4586 (extent-face (car extent-list
))
4591 ((eq ps-print-emacs-type
'emacs
)
4592 (let ((property-change from
)
4593 (overlay-change from
)
4594 (save-buffer-invisibility-spec buffer-invisibility-spec
)
4595 (buffer-invisibility-spec nil
))
4597 (and (< property-change to
) ; Don't search for property change
4598 ; unless previous search succeeded.
4599 (setq property-change
(next-property-change from nil to
)))
4600 (and (< overlay-change to
) ; Don't search for overlay change
4601 ; unless previous search succeeded.
4602 (setq overlay-change
(min (next-overlay-change from
) to
)))
4603 (setq position
(min property-change overlay-change
))
4604 ;; The code below is not quite correct,
4605 ;; because a non-nil overlay invisible property
4606 ;; which is inactive according to the current value
4607 ;; of buffer-invisibility-spec nonetheless overrides
4608 ;; a face text property.
4610 (cond ((let ((prop (get-text-property from
'invisible
)))
4611 ;; Decide whether this invisible property
4612 ;; really makes the text invisible.
4613 (if (eq save-buffer-invisibility-spec t
)
4615 (or (memq prop save-buffer-invisibility-spec
)
4616 (assq prop save-buffer-invisibility-spec
))))
4617 'emacs--invisible--face
)
4618 ((get-text-property from
'face
))
4620 (let ((overlays (overlays-at from
))
4621 (face-priority -
1)) ; text-property
4622 (while (and overlays
4623 (not (eq face
'emacs--invisible--face
)))
4624 (let* ((overlay (car overlays
))
4625 (overlay-invisible (overlay-get overlay
'invisible
))
4626 (overlay-priority (or (overlay-get overlay
'priority
)
4628 (and (> overlay-priority face-priority
)
4630 (cond ((if (eq save-buffer-invisibility-spec t
)
4631 (not (null overlay-invisible
))
4632 (or (memq overlay-invisible
4633 save-buffer-invisibility-spec
)
4634 (assq overlay-invisible
4635 save-buffer-invisibility-spec
)))
4636 'emacs--invisible--face
)
4637 ((overlay-get overlay
'face
))
4639 face-priority overlay-priority
)))
4640 (setq overlays
(cdr overlays
))))
4641 ;; Plot up to this record.
4642 (ps-plot-with-face from position face
)
4643 (setq from position
)))))
4644 (ps-plot-with-face from to face
))))
4646 (defun ps-generate-postscript (from to
)
4647 (ps-plot-region from to
0 nil
))
4649 (defun ps-generate (buffer from to genfunc
)
4651 (let ((from (min to from
))
4653 ;; This avoids trouble if chars with read-only properties
4654 ;; are copied into ps-spool-buffer.
4655 (inhibit-read-only t
))
4657 (narrow-to-region from to
)
4658 (and ps-razzle-dazzle
4659 (message "Formatting...%3d%%" (setq ps-razchunk
0)))
4660 (setq ps-source-buffer buffer
4661 ps-spool-buffer
(get-buffer-create ps-spool-buffer-name
))
4662 (ps-init-output-queue)
4663 (let (safe-marker completed-safely needs-begin-file
)
4666 (set-buffer ps-spool-buffer
)
4667 (set-buffer-multibyte nil
)
4669 ;; Get a marker and make it point to the current end of the
4670 ;; buffer, If an error occurs, we'll delete everything from
4671 ;; the end of this marker onwards.
4672 (setq safe-marker
(make-marker))
4673 (set-marker safe-marker
(point-max))
4675 (goto-char (point-min))
4676 (or (looking-at (regexp-quote ps-adobe-tag
))
4677 (setq needs-begin-file t
))
4679 (set-buffer ps-source-buffer
)
4681 (when needs-begin-file
4683 (ps-mule-initialize))
4684 (ps-mule-begin-job from to
)
4686 (set-buffer ps-source-buffer
)
4687 (funcall genfunc from to
)
4690 (ps-end-file needs-begin-file
)
4693 ;; Setting this variable tells the unwind form that the
4694 ;; the PostScript was generated without error.
4695 (setq completed-safely t
))
4697 ;; Unwind form: If some bad mojo occurred while generating
4698 ;; PostScript, delete all the PostScript that was generated.
4699 ;; This protects the previously spooled files from getting
4701 (and (markerp safe-marker
) (not completed-safely
)
4703 (set-buffer ps-spool-buffer
)
4704 (delete-region (marker-position safe-marker
) (point-max))))))
4706 (and ps-razzle-dazzle
(message "Formatting...done"))))))
4709 (defun ps-end-job ()
4711 (let ((total-lines (cdr ps-printing-region
))
4712 (total-pages (if ps-print-only-one-header
4716 (set-buffer ps-spool-buffer
)
4717 ;; Back to the PS output buffer to set the page count
4718 (goto-char (point-min))
4719 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t
)
4720 (replace-match (format "/Lines %d def\n/PageCount %d def"
4721 total-lines total-pages
) t
))))
4724 (defconst ps-printer-name-option
4725 (cond ((memq system-type
'(win32 w32 mswindows ms-dos windows-nt
))
4727 ((memq system-type
'(usq-unix-v dgux hpux irix
))
4733 ;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
4734 (defun ps-do-despool (filename)
4735 (if (or (not (boundp 'ps-spool-buffer
))
4736 (not (symbol-value 'ps-spool-buffer
)))
4737 (message "No spooled PostScript to print")
4740 (and ps-razzle-dazzle
(message "Saving..."))
4741 (set-buffer ps-spool-buffer
)
4742 (setq filename
(expand-file-name filename
))
4743 (let ((coding-system-for-write 'raw-text-unix
))
4744 (write-region (point-min) (point-max) filename
))
4745 (and ps-razzle-dazzle
(message "Wrote %s" filename
)))
4746 ;; Else, spool to the printer
4747 (and ps-razzle-dazzle
(message "Printing..."))
4749 (set-buffer ps-spool-buffer
)
4750 (let* ((coding-system-for-write 'raw-text-unix
)
4751 (ps-printer-name (or ps-printer-name
4752 (and (boundp 'printer-name
)
4755 (append (and (stringp ps-printer-name
)
4756 (list (concat ps-printer-name-option
4759 (apply (or ps-print-region-function
'call-process-region
)
4760 (point-min) (point-max) ps-lpr-command nil
4761 (and (fboundp 'start-process
) 0)
4763 (ps-flatten-list ; dynamic evaluation
4764 (mapcar 'ps-eval-switch ps-lpr-switches
)))))
4765 (and ps-razzle-dazzle
(message "Printing...done")))
4766 (kill-buffer ps-spool-buffer
)))
4768 ;; Dynamic evaluation
4769 (defun ps-eval-switch (arg)
4770 (cond ((stringp arg
) arg
)
4771 ((functionp arg
) (apply arg nil
))
4772 ((symbolp arg
) (symbol-value arg
))
4773 ((consp arg
) (apply (car arg
) (cdr arg
)))
4776 ;; `ps-flatten-list' is defined here (copied from "message.el" and
4777 ;; enhanced to handle dotted pairs as well) until we can get some
4778 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
4780 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
4781 ;; => (a b c d e f g h i j)
4783 (defun ps-flatten-list (&rest list
)
4784 (ps-flatten-list-1 list
))
4786 (defun ps-flatten-list-1 (list)
4787 (cond ((null list
) nil
)
4788 ((consp list
) (append (ps-flatten-list-1 (car list
))
4789 (ps-flatten-list-1 (cdr list
))))
4792 (defun ps-kill-emacs-check ()
4794 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
4795 (buffer-modified-p ps-buffer
)
4796 (y-or-n-p "Unprinted PostScript waiting; print now? ")
4798 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
4799 (buffer-modified-p ps-buffer
)
4800 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
4801 (error "Unprinted PostScript"))))
4803 (cond ((fboundp 'add-hook
)
4804 (funcall 'add-hook
'kill-emacs-hook
'ps-kill-emacs-check
))
4806 (message "Won't override existing `kill-emacs-hook'"))
4808 (setq kill-emacs-hook
'ps-kill-emacs-check
)))
4811 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4812 ;;; Sample Setup Code:
4815 ;; This stuff is for anybody that's brave enough to look this far,
4816 ;; and able to figure out how to use it. It isn't really part of
4817 ;; ps-print, but I'll leave it here in hopes it might be useful:
4819 ;; WARNING!!! The following code is *sample* code only.
4820 ;; Don't use it unless you understand what it does!
4822 (defmacro ps-prsc
()
4823 `(if (eq ps-print-emacs-type
'emacs
) [f22] 'f22))
4824 (defmacro ps-c-prsc ()
4825 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
4826 (defmacro ps-s-prsc ()
4827 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
4829 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
4830 ;; `ps-left-headers' specially for mail messages.
4831 (defun ps-rmail-mode-hook ()
4832 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
4833 (setq ps-header-lines 3
4835 ;; The left headers will display the message's subject, its
4836 ;; author, and the name of the folder it was in.
4837 '(ps-article-subject ps-article-author buffer-name)))
4839 ;; See `ps-gnus-print-article-from-summary'. This function does the
4840 ;; same thing for rmail.
4841 (defun ps-rmail-print-message-from-summary ()
4843 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
4845 ;; Used in `ps-rmail-print-article-from-summary',
4846 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
4847 (defun ps-print-message-from-summary (summary-buffer summary-default)
4848 (let ((ps-buf (or (and (boundp summary-buffer)
4849 (symbol-value summary-buffer))
4851 (and (get-buffer ps-buf)
4854 (ps-spool-buffer-with-faces)))))
4856 ;; Look in an article or mail message for the Subject: line. To be
4857 ;; placed in `ps-left-headers'.
4858 (defun ps-article-subject ()
4860 (goto-char (point-min))
4861 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
4862 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4865 ;; Look in an article or mail message for the From: line. Sorta-kinda
4866 ;; understands RFC-822 addresses and can pull the real name out where
4867 ;; it's provided. To be placed in `ps-left-headers'.
4868 (defun ps-article-author ()
4870 (goto-char (point-min))
4871 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
4872 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
4876 ;; Try first to match addresses that look like
4877 ;; thompson@wg2.waii.com (Jim Thompson)
4878 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
4879 (substring fromstring (match-beginning 1) (match-end 1)))
4881 ;; Next try to match addresses that look like
4882 ;; Jim Thompson <thompson@wg2.waii.com>
4883 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
4884 (substring fromstring (match-beginning 1) (match-end 1)))
4886 ;; Couldn't find a real name -- show the address instead.
4890 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
4891 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
4892 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
4893 ;; buffer enters that mode, so it would only work for the first time
4894 ;; we ran gnus. The second time, this hook wouldn't get set up. The
4895 ;; only alternative is `gnus-article-prepare-hook'.
4896 (defun ps-gnus-article-prepare-hook ()
4897 (setq ps-header-lines 3
4899 ;; The left headers will display the article's subject, its
4900 ;; author, and the newsgroup it was in.
4901 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
4903 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
4904 ;; `ps-left-headers' specially for mail messages.
4905 (defun ps-vm-mode-hook ()
4906 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
4907 (setq ps-header-lines 3
4909 ;; The left headers will display the message's subject, its
4910 ;; author, and the name of the folder it was in.
4911 '(ps-article-subject ps-article-author buffer-name)))
4913 ;; Every now and then I forget to switch from the *Summary* buffer to
4914 ;; the *Article* before hitting prsc, and a nicely formatted list of
4915 ;; article subjects shows up at the printer. This function, bound to
4916 ;; prsc for the gnus *Summary* buffer means I don't have to switch
4918 ;; sb: Updated for Gnus 5.
4919 (defun ps-gnus-print-article-from-summary ()
4921 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
4923 ;; See `ps-gnus-print-article-from-summary'. This function does the
4924 ;; same thing for vm.
4925 (defun ps-vm-print-message-from-summary ()
4927 (ps-print-message-from-summary 'vm-mail-buffer ""))
4929 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
4931 (defun ps-gnus-summary-setup ()
4932 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
4934 ;; Look in an article or mail message for the Subject: line. To be
4935 ;; placed in `ps-left-headers'.
4936 (defun ps-info-file ()
4938 (goto-char (point-min))
4939 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
4940 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4943 ;; Look in an article or mail message for the Subject: line. To be
4944 ;; placed in `ps-left-headers'.
4945 (defun ps-info-node ()
4947 (goto-char (point-min))
4948 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
4949 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4952 (defun ps-info-mode-hook ()
4953 (setq ps-left-header
4954 ;; The left headers will display the node name and file name.
4955 '(ps-info-node ps-info-file)))
4957 ;; WARNING! The following function is a *sample* only, and is *not*
4958 ;; meant to be used as a whole unless you understand what the effects
4959 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
4960 ;; I'd be very surprised if it was useful to *anybody*, without
4963 (defun ps-jts-ps-setup ()
4964 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
4965 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
4966 (global-set-key (ps-c-prsc) 'ps-despool)
4967 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
4968 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
4969 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
4970 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
4971 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
4972 (setq ps-spool-duplex t
4973 ps-print-color-p nil
4974 ps-lpr-command "lpr"
4975 ps-lpr-switches '("-Jjct,duplex_long"))
4978 ;; WARNING! The following function is a *sample* only, and is *not*
4979 ;; meant to be used as a whole unless it corresponds to your needs.
4980 ;; (In fact, this is a copy of Jack's setup for ps-print --
4981 ;; I would not be that surprised if it was useful to *anybody*,
4982 ;; without modification.)
4984 (defun ps-jack-setup ()
4985 (setq ps-print-color-p nil
4986 ps-lpr-command "lpr"
4991 ps-number-of-columns 2
4993 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
4994 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
4995 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
4996 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
4997 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
4998 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
4999 ps-header-line-pad .15
5001 ps-print-header-frame t
5006 ps-font-family 'Courier
5008 ps-header-font-family 'Helvetica
5009 ps-header-font-size 6
5010 ps-header-title-font-size 8)
5014 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5015 ;; To make this file smaller, some commands go in a separate file.
5016 ;; But autoload them here to make the separation invisible.
5018 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
5019 "Setup special ASCII font for STRING.
5020 STRING should contain only ASCII characters.")
5022 (autoload 'ps-mule-set-ascii-font "ps-mule"
5023 "Adjust current font if current charset is not ASCII.")
5025 (autoload 'ps-mule-plot-string "ps-mule"
5026 "Generate PostScript code for ploting characters in the region FROM and TO.
5028 It is assumed that all characters in this region belong to the same charset.
5030 Optional argument BG-COLOR specifies background color.
5034 (ENDPOS . RUN-WIDTH)
5036 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
5039 (autoload 'ps-mule-initialize "ps-mule"
5040 "Initialize global data for printing multi-byte characters.")
5042 (autoload 'ps-mule-begin-job "ps-mule"
5043 "Start printing job for multi-byte chars between FROM and TO.
5044 This checks if all multi-byte characters in the region are printable or not.")
5046 (autoload 'ps-mule-begin-page "ps-mule"
5047 "Initialize multi-byte charset for printing current page.")
5050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5054 ;;; ps-print.el ends here