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/22 09:12:07 vinicius>
15 (defconst ps-print-version
"5.1.2"
16 "ps-print.el, v 5.1.2 <2000/03/22 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
441 ;; paper-and-system catch the error, print on paper the error message and
442 ;; send back the error message to printing system.
444 ;; Any other value is treated as `paper'.
450 ;; If you have a duplex-capable printer (one that prints both sides of the
451 ;; paper), set `ps-spool-duplex' to t.
452 ;; ps-print will insert blank pages to make sure each buffer starts on the
453 ;; correct side of the paper.
455 ;; The variable `ps-spool-config' specifies who is the responsable for setting
456 ;; duplex and page size switches. Valid values are:
458 ;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
459 ;; Don't forget to set `ps-lpr-switches' to select duplex
460 ;; printing for your printer.
462 ;; setpagedevice duplex and page size are configured by ps-print using the
463 ;; setpagedevice PostScript operator.
465 ;; nil duplex and page size are configured by ps-print *not* using
466 ;; the setpagedevice PostScript operator.
468 ;; Any other value is treated as nil.
470 ;; The default value is `lpr-switches'.
472 ;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
473 ;; viewing file generated using landscape. Also on some printers,
474 ;; setpagedevice affects zebra stripes; on other printers,
475 ;; setpagedevice affects the left margin.
476 ;; Besides all that, if your printer does not have the paper size
477 ;; specified by setpagedevice, your printing will be aborted.
478 ;; So, if you need to use setpagedevice, set `ps-spool-config' to
479 ;; `setpagedevice', generate a test file and send it to your printer;
480 ;; if the printed file isn't ok, set `ps-spool-config' to nil.
482 ;; The variable `ps-spool-tumble' specifies how the page images on opposite
483 ;; sides of a sheet are oriented with respect to each other. If
484 ;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
485 ;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
486 ;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
487 ;; The default value is nil.
489 ;; Some printer system prints a header page and forces the first page be printed
490 ;; on header page back, when using duplex. If your printer system has this
491 ;; behavior, set variable `ps-banner-page-when-duplexing' to t.
493 ;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
494 ;; skipped. It's like the very first character of buffer (or region) is ^L
497 ;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
504 ;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
505 ;; paper. The value specified must be between 1 and 100. The default is 1.
507 ;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
508 ;; to a high value (for example, 23). If this happens, set a lower value.
510 ;; The variable `ps-n-up-margin' specifies the margin in points between the
511 ;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
514 ;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
517 ;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
518 ;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
519 ;; filling example using a 3x4 page matrix:
521 ;; left-top 1 2 3 4 left-bottom 9 10 11 12
523 ;; 9 10 11 12 1 2 3 4
525 ;; right-top 4 3 2 1 right-bottom 12 11 10 9
527 ;; 12 11 10 9 4 3 2 1
529 ;; top-left 1 4 7 10 bottom-left 3 6 9 12
533 ;; top-right 10 7 4 1 bottom-right 12 9 6 3
537 ;; Any other value is treated as left-top.
539 ;; The default value is left-top.
542 ;; Control And 8-bit Characters
543 ;; ----------------------------
545 ;; The variable `ps-print-control-characters' specifies whether you want to see
546 ;; a printable form for control and 8-bit characters, that is, instead of
547 ;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
549 ;; Valid values for `ps-print-control-characters' are:
551 ;; 8-bit This is the value to use when you want an ASCII encoding of
552 ;; any control or non-ASCII character. Control characters are
553 ;; encoded as "^D", and non-ASCII characters have an
556 ;; control-8-bit This is the value to use when you want an ASCII encoding of
557 ;; any control character, whether it is 7 or 8-bit.
558 ;; European 8-bits accented characters are printed according
561 ;; control Only ASCII control characters have an ASCII encoding.
562 ;; European 8-bits accented characters are printed according
565 ;; nil No ASCII encoding. Any character is printed according the
568 ;; Any other value is treated as nil.
570 ;; The default is `control-8-bit'.
572 ;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
575 ;; Printing Multi-byte Buffer
576 ;; --------------------------
578 ;; See ps-mule.el for documentation.
584 ;; The variable `ps-line-number' specifies whether to number each line;
585 ;; non-nil means do so. The default is nil (don't number each line).
591 ;; Zebra stripes are a kind of background that appear "underneath" the text
592 ;; and can make the text easier to read. They look like this:
594 ;; XXXXXXXXXXXXXXXXXXXXXXXX
595 ;; XXXXXXXXXXXXXXXXXXXXXXXX
596 ;; XXXXXXXXXXXXXXXXXXXXXXXX
600 ;; XXXXXXXXXXXXXXXXXXXXXXXX
601 ;; XXXXXXXXXXXXXXXXXXXXXXXX
602 ;; XXXXXXXXXXXXXXXXXXXXXXXX
604 ;; The blocks of X's represent rectangles filled with a light gray color.
605 ;; Each rectangle extends all the way across the page.
607 ;; The height, in lines, of each rectangle is controlled by
608 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
609 ;; The distance between stripes equals the height of a stripe.
611 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
612 ;; Non-nil means yes, nil means no. The default is nil.
614 ;; The variable `ps-zebra-gray' controls the zebra stripes gray scale.
615 ;; It should be a float number between 0.0 (black color) and 1.0 (white color).
616 ;; The default is 0.95.
618 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
624 ;; ps-print has the following hook variables:
627 ;; It is evaluated once before any printing process. This is the right
628 ;; place to initialize ps-print global data.
629 ;; For an example, see section Adding a New Font Family.
631 ;; `ps-print-begin-sheet-hook'
632 ;; It is evaluated on each beginning of sheet of paper.
633 ;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
636 ;; `ps-print-begin-page-hook'
637 ;; It is evaluated on each beginning of page, except in the beginning
638 ;; of page that `ps-print-begin-sheet-hook' is evaluated.
640 ;; `ps-print-begin-column-hook'
641 ;; It is evaluated on each beginning of column, except in the beginning
642 ;; of column that `ps-print-begin-page-hook' is evaluated or that
643 ;; `ps-print-begin-sheet-hook' is evaluated.
649 ;; ps-print now knows rather precisely some fonts: the variable
650 ;; `ps-font-info-database' contains information for a list of font families
651 ;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
652 ;; `NewCenturySchlbk'). Each font family contains the font names for standard,
653 ;; bold, italic and bold-italic characters, a reference size (usually 10) and
654 ;; the corresponding line height, width of a space and average character width.
656 ;; The variable `ps-font-family' determines which font family is to be used for
657 ;; ordinary text. If its value does not correspond to a known font family, an
658 ;; error message is printed into the `*Messages*' buffer, which lists the
659 ;; currently available font families.
661 ;; The variable `ps-font-size' determines the size (in points) of the font for
662 ;; ordinary text, when generating PostScript. Its value is a float or a cons of
663 ;; floats which has the following form:
665 ;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
667 ;; Similarly, the variable `ps-header-font-family' determines which font family
668 ;; is to be used for text in the header.
670 ;; The variable `ps-header-font-size' determines the font size, in points, for
671 ;; text in the header (similar to `ps-font-size').
673 ;; The variable `ps-header-title-font-size' determines the font size, in points,
674 ;; for the top line of text in the header (similar to `ps-font-size').
677 ;; Adding a New Font Family
678 ;; ------------------------
680 ;; To use a new font family, you MUST first teach ps-print
681 ;; this font, i.e., add its information to `ps-font-info-database',
682 ;; otherwise ps-print cannot correctly place line and page breaks.
684 ;; For example, assuming `Helvetica' is unknown,
685 ;; you first need to do the following ONLY ONCE:
687 ;; - create a new buffer
688 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
689 ;; - open this file and find the line:
690 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
691 ;; - delete the leading `%' (which is the PostScript comment character)
692 ;; - replace in this line `Courier' by the new font (say `Helvetica')
694 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
695 ;; - send this file to the printer (or to ghostscript).
696 ;; You should read the following on the output page:
698 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
699 ;; and a crude estimate of average character width is 5.09243
701 ;; - Add these values to the `ps-font-info-database':
702 ;; (setq ps-font-info-database
704 ;; '((Helvetica ; the family key
705 ;; (fonts (normal . "Helvetica")
706 ;; (bold . "Helvetica-Bold")
707 ;; (italic . "Helvetica-Oblique")
708 ;; (bold-italic . "Helvetica-BoldOblique"))
710 ;; (line-height . 11.56)
711 ;; (space-width . 2.78)
712 ;; (avg-char-width . 5.09243)))
713 ;; ps-font-info-database))
714 ;; - Now you can use this font family with any size:
715 ;; (setq ps-font-family 'Helvetica)
716 ;; - if you want to use this family in another emacs session, you must
717 ;; put into your `~/.emacs':
718 ;; (require 'ps-print)
719 ;; (setq ps-font-info-database (append ...)))
720 ;; if you don't want to load ps-print, you have to copy the whole value:
721 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
722 ;; or, use `ps-print-hook' (see section Hooks):
723 ;; (add-hook 'ps-print-hook
725 ;; (or (assq 'Helvetica ps-font-info-database)
726 ;; (setq ps-font-info-database (append ...)))))
728 ;; You can create new `mixed' font families like:
730 ;; (fonts (normal . "Courier-Bold")
731 ;; (bold . "Helvetica")
732 ;; (italic . "Zapf-Chancery-MediumItalic")
733 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
734 ;; (w3-table-hack-x-face . "LineDrawNormal"))
736 ;; (line-height . 10.55)
737 ;; (space-width . 6.0)
738 ;; (avg-char-width . 6.0))
740 ;; Now you can use your new font family with any size:
741 ;; (setq ps-font-family 'my-mixed-family)
743 ;; Note that on above example the `w3-table-hack-x-face' entry refers to
744 ;; a face symbol, so when printing this face it'll be used the font
745 ;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
746 ;; use bold and/or italic attribute, the corresponding entry (bold, italic
747 ;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
749 ;; Note also that the font family entry order is irrelevant, so the above
750 ;; example could also be written:
753 ;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
754 ;; (bold . "Helvetica")
755 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
756 ;; (italic . "Zapf-Chancery-MediumItalic")
757 ;; (normal . "Courier-Bold"))
758 ;; (avg-char-width . 6.0)
759 ;; (space-width . 6.0)
760 ;; (line-height . 10.55))
762 ;; Despite the note above, it is recommended that some convention about
763 ;; entry order be used.
765 ;; You can get information on all the fonts resident in YOUR printer
766 ;; by uncommenting the line:
767 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
769 ;; The PostScript file should be sent to YOUR PostScript printer.
770 ;; If you send it to ghostscript or to another PostScript printer,
771 ;; you may get slightly different results.
772 ;; Anyway, as ghostscript fonts are autoload, you won't get
776 ;; How Ps-Print Deals With Faces
777 ;; -----------------------------
779 ;; The ps-print-*-with-faces commands attempt to determine which faces
780 ;; should be printed in bold or italic, but their guesses aren't
781 ;; always right. For example, you might want to map colors into faces
782 ;; so that blue faces print in bold, and red faces in italic.
784 ;; It is possible to force ps-print to consider specific faces bold,
785 ;; italic or underline, no matter what font they are displayed in, by setting
786 ;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
787 ;; These variables contain lists of faces that ps-print should consider bold,
788 ;; italic or underline; to set them, put code like the following into your
791 ;; (setq ps-bold-faces '(my-blue-face))
792 ;; (setq ps-italic-faces '(my-red-face))
793 ;; (setq ps-underlined-faces '(my-green-face))
795 ;; Faces like bold-italic that are both bold and italic should go in
798 ;; ps-print keeps internal lists of which fonts are bold and which are
799 ;; italic; these lists are built the first time you invoke ps-print.
800 ;; For the sake of efficiency, the lists are built only once; the same
801 ;; lists are referred in later invocations of ps-print.
803 ;; Because these lists are built only once, it's possible for them to
804 ;; get out of sync, if a face changes, or if new faces are added. To
805 ;; get the lists back in sync, you can set the variable
806 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
807 ;; next time ps-print is invoked. If you need that the lists always be
808 ;; rebuilt when ps-print is invoked, set the variable
809 ;; `ps-always-build-face-reference' to t.
812 ;; How Ps-Print Deals With Color
813 ;; -----------------------------
815 ;; ps-print detects faces with foreground and background colors
816 ;; defined and embeds color information in the PostScript image.
817 ;; The default foreground and background colors are defined by the
818 ;; variables `ps-default-fg' and `ps-default-bg'.
819 ;; On black-and-white printers, colors are displayed in grayscale.
820 ;; To turn off color output, set `ps-print-color-p' to nil.
823 ;; How Ps-Print Maps Faces
824 ;; -----------------------
826 ;; As ps-print uses PostScript to print buffers, it is possible to have
827 ;; other attributes associated with faces. So the new attributes used
830 ;; strikeout - like underline, but the line is in middle of text.
831 ;; overline - like underline, but the line is over the text.
832 ;; shadow - text will have a shadow.
833 ;; box - text will be surrounded by a box.
834 ;; outline - print characters as hollow outlines.
836 ;; See the documentation for `ps-extend-face'.
838 ;; Let's, for example, remap `font-lock-keyword-face' to another foreground
839 ;; color and bold attribute:
841 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
843 ;; If you want to use a new face, define it first with `defface',
844 ;; and then call `ps-extend-face' to specify how to print it.
847 ;; How Ps-Print Has A Text And/Or Image On Background
848 ;; --------------------------------------------------
850 ;; ps-print can print texts and/or EPS PostScript images on background; it is
851 ;; possible to define the following text attributes: font name, font size,
852 ;; initial position, angle, gray scale and pages to print.
854 ;; It has the following EPS PostScript images attributes: file name containing
855 ;; the image, initial position, X and Y scales, angle and pages to print.
857 ;; See documentation for `ps-print-background-text' and
858 ;; `ps-print-background-image'.
860 ;; For example, if we wish to print text "preliminary" on all pages and text
861 ;; "special" on page 5 and from page 11 to page 17, we could specify:
863 ;; (setq ps-print-background-text
866 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
867 ;; ; (upper left corner)
869 ;; "PrintHeight neg PrintPageWidth atan" ; angle
870 ;; 5 (11 . 17)) ; page list
873 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
874 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
877 ;; (setq ps-print-background-image
878 ;; '(("~/images/EPS-image1.ps"
879 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
880 ;; ("~/images/EPS-image2.ps"
881 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
882 ;; ; (upper left corner)
884 ;; 5 (11 . 17)) ; page list
887 ;; If it is not possible to read (or does not exist) an image file, that file
890 ;; The printing order is:
892 ;; 1. Print zebra stripes
893 ;; 2. Print background texts that it should be on all pages
894 ;; 3. Print background images that it should be on all pages
895 ;; 4. Print background texts only for current page (if any)
896 ;; 5. Print background images only for current page (if any)
898 ;; 7. Print buffer text (with faces, if specified) and line number
904 ;; Some tools are provided to help you customize your font setup.
906 ;; `ps-setup' returns (some part of) the current setup.
908 ;; To avoid wrapping too many lines, you may want to adjust the
909 ;; left and right margins and the font size. On UN*X systems, do:
910 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
911 ;; to determine the longest lines of your file.
912 ;; Then, the command `ps-line-lengths' will give you the correspondence
913 ;; between a line length (number of characters) and the maximum font
914 ;; size which doesn't wrap such a line with the current ps-print setup.
916 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
917 ;; the correspondence between a number of pages and the maximum font
918 ;; size which allow the number of lines of the current buffer or of
919 ;; its current region to fit in this number of pages.
921 ;; NOTE: line folding is not taken into account in this process and could
922 ;; change the results.
924 ;; The command `ps-print-customize' activates a customization buffer for
928 ;; New since version 1.5
929 ;; ---------------------
931 ;; Color output capability.
932 ;; Automatic detection of font attributes (bold, italic).
933 ;; Configurable headers with page numbers.
935 ;; Support for different paper sizes.
936 ;; Better conformance to PostScript Document Structure Conventions.
939 ;; New since version 2.8
940 ;; ---------------------
942 ;; [vinicius] 20000310 Vinicius Jose Latorre <vinicius@cpqd.com.br>
944 ;; PostScript error handler.
945 ;; `ps-user-defined-prologue' and `ps-error-handler-message'.
947 ;; [vinicius] 991211 Vinicius Jose Latorre <vinicius@cpqd.com.br>
949 ;; `ps-print-customize'.
951 ;; [vinicius] 990703 Vinicius Jose Latorre <vinicius@cpqd.com.br>
953 ;; Better customization.
954 ;; `ps-banner-page-when-duplexing' and `ps-zebra-gray'.
956 ;; [vinicius] 990513 Vinicius Jose Latorre <vinicius@cpqd.com.br>
959 ;; Hook: `ps-print-begin-sheet-hook'.
961 ;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
963 ;; `ps-print-region-function'
965 ;; [vinicius] 990301 Vinicius Jose Latorre <vinicius@cpqd.com.br>
967 ;; PostScript tumble and setpagedevice.
969 ;; [vinicius] 980922 Vinicius Jose Latorre <vinicius@cpqd.com.br>
971 ;; PostScript prologue header comment insertion.
972 ;; Skip invisible text better.
974 ;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
976 ;; Multi-byte buffer handling.
978 ;; [vinicius] 980306 Vinicius Jose Latorre <vinicius@cpqd.com.br>
980 ;; Skip invisible text.
982 ;; [vinicius] 971130 Vinicius Jose Latorre <vinicius@cpqd.com.br>
984 ;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
985 ;; `ps-print-begin-column-hook'.
986 ;; Put one header per page over the columns.
987 ;; Better database font management.
988 ;; Better control characters handling.
990 ;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
992 ;; Dynamic evaluation at print time of `ps-lpr-switches'.
993 ;; Handle control characters.
995 ;; New face attributes.
998 ;; Text and/or image on background.
1000 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
1002 ;; Font family and float size for text and header.
1004 ;; Multiple columns.
1005 ;; Tools for page setup.
1008 ;; Known bugs and limitations of ps-print
1009 ;; --------------------------------------
1011 ;; Although color printing will work in XEmacs 19.12, it doesn't work
1012 ;; well; in particular, bold or italic fonts don't print in the right
1013 ;; background color.
1015 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
1017 ;; Automatic font-attribute detection doesn't work well, especially
1018 ;; with hilit19 and older versions of get-create-face. Users having
1019 ;; problems with auto-font detection should use the lists
1020 ;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
1021 ;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
1023 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
1024 ;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
1025 ;; `ps-underlined-faces' instead.
1027 ;; Still too slow; could use some hand-optimization.
1029 ;; Default background color isn't working.
1031 ;; Faces are always treated as opaque.
1033 ;; Epoch and Emacs 19 not supported. At all.
1035 ;; Fixed-pitch fonts work better for line folding, but are not required.
1037 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
1038 ;; of folding lines.
1044 ;; Avoid page break inside a paragraph.
1045 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
1046 ;; Improve the memory management for big files (hard?).
1047 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1048 ;; of folding lines.
1054 ;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for user defined PostScript
1055 ;; prologue code suggestion.
1057 ;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
1059 ;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1062 ;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1065 ;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1066 ;; `ps-print-control-characters' variable documentation.
1068 ;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1069 ;; database font management.
1071 ;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
1072 ;; header per page over the columns and correct line numbers when printing a
1075 ;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1076 ;; print time of `ps-lpr-switches'.
1078 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1079 ;; (his code was severely modified, but the main idea was kept).
1081 ;; Thanks to some suggestions on:
1082 ;; * Face color map: Marco Melgazzi <marco@techie.com>
1083 ;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
1084 ;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
1086 ;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1087 ;; I started from. [vinicius]
1089 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1092 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1093 ;; color and the invisible property.
1095 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1096 ;; the initial port to Emacs 19. His code is no longer part of
1097 ;; ps-print, but his work is still appreciated.
1099 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1100 ;; for adding underline support. Their code also is no longer part of
1101 ;; ps-print, but their efforts are not forgotten.
1103 ;; Thanks also to all of you who mailed code to add features to
1104 ;; ps-print; although I didn't use your code, I still appreciate your
1105 ;; sharing it with me.
1107 ;; Thanks to all who mailed comments, encouragement, and criticism.
1108 ;; Thanks also to all who responded to my survey; I had too many
1109 ;; responses to reply to them all, but I greatly appreciate your
1113 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1117 (unless (featurep 'lisp-float-type
)
1118 (error "`ps-print' requires floating point support"))
1121 ;; For Emacs 20.2 and the earlier version.
1123 (or (fboundp 'set-buffer-multibyte
)
1124 (defun set-buffer-multibyte (arg)
1125 (setq enable-multibyte-characters arg
)))
1127 (or (fboundp 'string-as-unibyte
)
1128 (defun string-as-unibyte (arg) arg
))
1130 (or (fboundp 'string-as-multibyte
)
1131 (defun string-as-multibyte (arg) arg
))
1133 (or (fboundp 'charset-after
)
1134 (defun charset-after (&optional arg
)
1135 (char-charset (char-after arg
))))
1138 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1142 ;;; Interface to the command system
1144 (defgroup postscript nil
1149 (defgroup ps-print nil
1150 "PostScript generator for Emacs 19"
1155 (defgroup ps-print-horizontal nil
1156 "Horizontal page layout"
1161 (defgroup ps-print-vertical nil
1162 "Vertical page layout"
1167 (defgroup ps-print-header nil
1173 (defgroup ps-print-font nil
1174 "Fonts customization"
1179 (defgroup ps-print-color nil
1180 "Color customization"
1185 (defgroup ps-print-face nil
1186 "Faces customization"
1192 (defgroup ps-print-n-up nil
1193 "N-up customization"
1198 (defgroup ps-print-zebra nil
1199 "Zebra customization"
1204 (defgroup ps-print-background nil
1205 "Background customization"
1210 (defgroup ps-print-printer nil
1211 "Printer customization"
1216 (defgroup ps-print-page nil
1217 "Page customization"
1223 (defcustom ps-error-handler-message
'paper
1224 "*Specify where the error handler message should be sent.
1228 `none' catch the error and *DON'T* send any message.
1230 `paper' catch the error and print on paper the error message.
1232 `system' catch the error and send back the error message to
1235 `paper-and-system' catch the error, print on paper the error message and
1236 send back the error message to printing system.
1238 Any other value is treated as `paper'."
1239 :type
'(choice :tag
"Error Handler Message"
1240 (const none
) (const paper
)
1241 (const system
) (const paper-and-system
))
1244 (defcustom ps-user-defined-prologue nil
1245 "*User defined PostScript prologue code inserted before all prologue code.
1247 `ps-user-defined-prologue' may be a string or a symbol function which returns a
1248 string. Note that this string is inserted after `ps-adobe-tag' and PostScript
1249 prologue comments, and before ps-print PostScript prologue code section. That
1250 is, this string is inserted after error handler initialization and before
1253 It's recommended to initiate and terminate the string with \"\\n\".
1255 It's strongly recommended only insert PostScript code and/or comments specific
1256 for your printing system particularities. For example, some special
1257 initialization that only your printing system needs.
1259 Do not insert code for duplex printing, n-up printing or error handler, ps-print
1260 handles this in a suitable way.
1262 For more information about PostScript, see:
1263 PostScript Language Reference Manual (2nd edition)
1264 Adobe Systems Incorporated"
1265 :type
'(choice :tag
"User Defined Prologue"
1266 string symbol
(other :tag
"nil" nil
))
1269 (defcustom ps-print-prologue-header nil
1270 "*PostScript prologue header comments besides that ps-print generates.
1272 `ps-print-prologue-header' may be a string or a symbol function which
1273 returns a string. Note that this string is inserted on PostScript prologue
1274 header section which is used to define some document characteristic through
1275 PostScript special comments, like \"%%Requirements: jog\\n\".
1277 ps-print always inserts the %%Requirements: comment, so if you need to insert
1278 more requirements put them first in `ps-print-prologue-header' using the
1279 \"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1280 requirements and set %%LanguageLevel: to 2, do:
1282 (setq ps-print-prologue-header
1283 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1285 The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1287 Do not forget to terminate the string with \"\\n\".
1289 For more information about PostScript document comments, see:
1290 PostScript Language Reference Manual (2nd edition)
1291 Adobe Systems Incorporated
1292 Appendix G: Document Structuring Conventions -- Version 3.0"
1293 :type
'(choice :tag
"Prologue Header"
1294 string symbol
(other :tag
"nil" nil
))
1297 (defcustom ps-printer-name
(and (boundp 'printer-name
)
1299 "*The name of a local printer for printing PostScript files.
1301 On Unix-like systems, a string value should be a name understood by
1302 lpr's -P option; a value of nil means use the value of `printer-name'
1303 instead. Any other value will be ignored.
1305 On MS-DOS and MS-Windows systems, a string value is taken as the name of
1306 the printer device or port to which PostScript files are written,
1307 provided `ps-lpr-command' is \"\". By default it is the same as
1308 `printer-name'; typical non-default settings would be \"LPT1\" to
1309 \"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1310 serial printers, or \"//hostname/printer\" for a shared network printer.
1311 You can also set it to a name of a file, in which case the output gets
1312 appended to that file. \(Note that `ps-print' package already has
1313 facilities for printing to a file, so you might as well use them instead
1314 of changing the setting of this variable.\) If you want to silently
1315 discard the printed output, set this to \"NUL\"."
1316 :type
'(choice :tag
"Printer Name"
1317 file
(other :tag
"Pipe to ps-lpr-command" pipe
))
1318 :group
'ps-print-printer
)
1320 (defcustom ps-lpr-command lpr-command
1321 "*Name of program for printing a PostScript file.
1323 On MS-DOS and MS-Windows systems, if the value is an empty string then
1324 Emacs will write directly to the printer port named by `ps-printer-name'.
1325 The programs `print' and `nprint' (the standard print programs on Windows
1326 NT and Novell Netware respectively) are handled specially, using
1327 `ps-printer-name' as the destination for output; any other program is
1328 treated like `lpr' except that an explicit filename is given as the last
1331 :group
'ps-print-printer
)
1333 (defcustom ps-lpr-switches lpr-switches
1334 "*A list of extra switches to pass to `ps-lpr-command'."
1335 :type
'(repeat string
)
1336 :group
'ps-print-printer
)
1338 (defcustom ps-print-region-function nil
1339 "*Specify a function to print the region on a PostScript printer.
1340 See definition of `call-process-region' for calling conventions. The fourth and
1341 the sixth arguments are both nil."
1343 :group
'ps-print-printer
)
1347 ;; All page dimensions are in PostScript points.
1348 ;; 1 inch == 2.54 cm == 72 points
1349 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1351 ;; Letter 8.5 inch x 11.0 inch
1352 ;; Legal 8.5 inch x 14.0 inch
1353 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1355 ;; LetterSmall 7.68 inch x 10.16 inch
1356 ;; Tabloid 11.0 inch x 17.0 inch
1357 ;; Ledger 17.0 inch x 11.0 inch
1358 ;; Statement 5.5 inch x 8.5 inch
1359 ;; Executive 7.5 inch x 10.0 inch
1360 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1361 ;; A4Small 7.47 inch x 10.85 inch
1362 ;; B4 10.125 inch x 14.33 inch
1363 ;; B5 7.16 inch x 10.125 inch
1365 (defcustom ps-page-dimensions-database
1366 (list (list 'a4
(/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1367 (list 'a3
(/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1368 (list 'letter
(* 72 8.5) (* 72 11.0) "Letter")
1369 (list 'legal
(* 72 8.5) (* 72 14.0) "Legal")
1370 (list 'letter-small
(* 72 7.68) (* 72 10.16) "LetterSmall")
1371 (list 'tabloid
(* 72 11.0) (* 72 17.0) "Tabloid")
1372 (list 'ledger
(* 72 17.0) (* 72 11.0) "Ledger")
1373 (list 'statement
(* 72 5.5) (* 72 8.5) "Statement")
1374 (list 'executive
(* 72 7.5) (* 72 10.0) "Executive")
1375 (list 'a4small
(* 72 7.47) (* 72 10.85) "A4Small")
1376 (list 'b4
(* 72 10.125) (* 72 14.33) "B4")
1377 (list 'b5
(* 72 7.16) (* 72 10.125) "B5"))
1378 "*List associating a symbolic paper type to its width, height and doc media.
1379 See `ps-paper-type'."
1380 :type
'(repeat (list :tag
"Paper Type"
1381 (symbol :tag
"Name")
1382 (number :tag
"Width")
1383 (number :tag
"Height")
1384 (string :tag
"Media")))
1385 :group
'ps-print-page
)
1388 (defcustom ps-paper-type
'letter
1389 "*Specify the size of paper to format for.
1390 Should be one of the paper types defined in `ps-page-dimensions-database', for
1391 example `letter', `legal' or `a4'."
1392 :type
'(symbol :validate
(lambda (wid)
1393 (if (assq (widget-value wid
)
1394 ps-page-dimensions-database
)
1396 (widget-put wid
:error
"Unknown paper size")
1398 :group
'ps-print-page
)
1400 (defcustom ps-landscape-mode nil
1401 "*Non-nil means print in landscape mode."
1403 :group
'ps-print-page
)
1405 (defcustom ps-print-control-characters
'control-8-bit
1406 "*Specify the printable form for control and 8-bit characters.
1407 That is, instead of sending, for example, a ^D (\\004) to printer,
1408 it is sent the string \"^D\".
1412 `8-bit' This is the value to use when you want an ASCII encoding of
1413 any control or non-ASCII character. Control characters are
1414 encoded as \"^D\", and non-ASCII characters have an
1417 `control-8-bit' This is the value to use when you want an ASCII encoding of
1418 any control character, whether it is 7 or 8-bit.
1419 European 8-bits accented characters are printed according
1422 `control' Only ASCII control characters have an ASCII encoding.
1423 European 8-bits accented characters are printed according
1426 nil No ASCII encoding. Any character is printed according the
1429 Any other value is treated as nil."
1430 :type
'(choice :tag
"Control Char"
1431 (const 8-bit
) (const control-8-bit
)
1432 (const control
) (other :tag
"nil" nil
))
1435 (defcustom ps-n-up-printing
1
1436 "*Specify the number of pages per sheet paper."
1438 :tag
"N Up Printing"
1441 (if (and (< 0 (widget-value wid
))
1442 (<= (widget-value wid
) 100))
1446 "Number of pages per sheet paper must be between 1 and 100.")
1448 :group
'ps-print-n-up
)
1450 (defcustom ps-n-up-margin
(/ (* 72 1.0) 2.54) ; 1 cm
1451 "*Specify the margin in points between the sheet border and n-up printing."
1453 :group
'ps-print-n-up
)
1455 (defcustom ps-n-up-border-p t
1456 "*Non-nil means a border is drawn around each page."
1458 :group
'ps-print-n-up
)
1460 (defcustom ps-n-up-filling
'left-top
1461 "*Specify how page matrix is filled on each sheet of paper.
1463 Following are the valid values for `ps-n-up-filling' with a filling example
1464 using a 3x4 page matrix:
1466 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1470 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1474 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1478 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1482 Any other value is treated as `left-top'."
1483 :type
'(choice :tag
"N-Up Filling"
1484 (const left-top
) (const left-bottom
)
1485 (const right-top
) (const right-bottom
)
1486 (const top-left
) (const bottom-left
)
1487 (const top-right
) (const bottom-right
))
1488 :group
'ps-print-n-up
)
1490 (defcustom ps-number-of-columns
(if ps-landscape-mode
2 1)
1491 "*Specify the number of columns"
1495 (defcustom ps-zebra-stripes nil
1496 "*Non-nil means print zebra stripes.
1497 See also documentation for `ps-zebra-stripe-height' and `ps-zebra-gray'."
1499 :group
'ps-print-zebra
)
1501 (defcustom ps-zebra-stripe-height
3
1502 "*Number of zebra stripe lines.
1503 See also documentation for `ps-zebra-stripes' and `ps-zebra-gray'."
1505 :group
'ps-print-zebra
)
1507 (defcustom ps-zebra-gray
0.95
1508 "*Zebra stripe gray scale.
1509 See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
1511 :group
'ps-print-zebra
)
1513 (defcustom ps-line-number nil
1514 "*Non-nil means print line number."
1518 (defcustom ps-print-background-image nil
1519 "*EPS image list to be printed on background.
1523 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1525 FILENAME is a file name which contains an EPS image or some PostScript
1526 programming like EPS.
1527 FILENAME is ignored, if it doesn't exist or is read protected.
1529 X and Y are relative positions on paper to put the image.
1530 If X and Y are nil, the image is centralized on paper.
1532 XSCALE and YSCALE are scale factor to be applied to image before printing.
1533 If XSCALE and YSCALE are nil, the original size is used.
1535 ROTATION is the image rotation angle; if nil, the default is 0.
1537 PAGES designates the page to print background image.
1538 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1540 If PAGES is nil, print background image on all pages.
1542 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1543 an integer number or a string. If it is a string, the string should contain
1544 PostScript programming that returns a float or integer value.
1546 For example, if you wish to print an EPS image on all pages do:
1548 '((\"~/images/EPS-image.ps\"))"
1549 :type
'(repeat (list (file :tag
"EPS File")
1550 (choice :tag
"X" number string
(const nil
))
1551 (choice :tag
"Y" number string
(const nil
))
1552 (choice :tag
"X Scale" number string
(const nil
))
1553 (choice :tag
"Y Scale" number string
(const nil
))
1554 (choice :tag
"Rotation" number string
(const nil
))
1555 (repeat :tag
"Pages" :inline t
1556 (radio (integer :tag
"Page")
1558 (integer :tag
"From")
1559 (integer :tag
"To"))))))
1560 :group
'ps-print-background
)
1562 (defcustom ps-print-background-text nil
1563 "*Text list to be printed on background.
1567 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1569 STRING is the text to be printed on background.
1571 X and Y are positions on paper to put the text.
1572 If X and Y are nil, the text is positioned at lower left corner.
1574 FONT is a font name to be used on printing the text.
1575 If nil, \"Times-Roman\" is used.
1577 FONTSIZE is font size to be used, if nil, 200 is used.
1579 GRAY is the text gray factor (should be very light like 0.8).
1580 If nil, the default is 0.85.
1582 ROTATION is the text rotation angle; if nil, the angle is given by
1583 the diagonal from lower left corner to upper right corner.
1585 PAGES designates the page to print background text.
1586 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1588 If PAGES is nil, print background text on all pages.
1590 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1591 an integer number or a string. If it is a string, the string should contain
1592 PostScript programming that returns a float or integer value.
1594 For example, if you wish to print text \"Preliminary\" on all pages do:
1596 '((\"Preliminary\"))"
1597 :type
'(repeat (list (string :tag
"Text")
1598 (choice :tag
"X" number string
(const nil
))
1599 (choice :tag
"Y" number string
(const nil
))
1600 (choice :tag
"Font" string
(const nil
))
1601 (choice :tag
"Fontsize" number string
(const nil
))
1602 (choice :tag
"Gray" number string
(const nil
))
1603 (choice :tag
"Rotation" number string
(const nil
))
1604 (repeat :tag
"Pages" :inline t
1605 (radio (integer :tag
"Page")
1607 (integer :tag
"From")
1608 (integer :tag
"To"))))))
1609 :group
'ps-print-background
)
1611 ;;; Horizontal layout
1613 ;; ------------------------------------------
1615 ;; | lm | text | ic | text | ic | text | rm |
1617 ;; ------------------------------------------
1619 (defcustom ps-left-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1620 "*Left margin in points (1/72 inch)."
1622 :group
'ps-print-horizontal
)
1624 (defcustom ps-right-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1625 "*Right margin in points (1/72 inch)."
1627 :group
'ps-print-horizontal
)
1629 (defcustom ps-inter-column
(/ (* 72 2.0) 2.54) ; 2 cm
1630 "*Horizontal space between columns in points (1/72 inch)."
1632 :group
'ps-print-horizontal
)
1648 (defcustom ps-bottom-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1649 "*Bottom margin in points (1/72 inch)."
1651 :group
'ps-print-vertical
)
1653 (defcustom ps-top-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1654 "*Top margin in points (1/72 inch)."
1656 :group
'ps-print-vertical
)
1658 (defcustom ps-header-offset
(/ (* 72 1.0) 2.54) ; 1.0 cm
1659 "*Vertical space in points (1/72 inch) between the main text and the header."
1661 :group
'ps-print-vertical
)
1663 (defcustom ps-header-line-pad
0.15
1664 "*Portion of a header title line height to insert between the header frame
1665 and the text it contains, both in the vertical and horizontal directions."
1667 :group
'ps-print-vertical
)
1671 (defcustom ps-print-header t
1672 "*Non-nil means print a header at the top of each page.
1673 By default, the header displays the buffer name, page number, and, if
1674 the buffer is visiting a file, the file's directory. Headers are
1675 customizable by changing variables `ps-left-header' and
1678 :group
'ps-print-header
)
1680 (defcustom ps-print-only-one-header nil
1681 "*Non-nil means print only one header at the top of each page.
1682 This is useful when printing more than one column, so it is possible
1683 to have only one header over all columns or one header per column.
1684 See also `ps-print-header'."
1686 :group
'ps-print-header
)
1688 (defcustom ps-print-header-frame t
1689 "*Non-nil means draw a gaudy frame around the header."
1691 :group
'ps-print-header
)
1693 (defcustom ps-header-lines
2
1694 "*Number of lines to display in page header, when generating PostScript."
1696 :group
'ps-print-header
)
1698 (defcustom ps-show-n-of-n t
1699 "*Non-nil means show page numbers as N/M, meaning page N of M.
1700 NOTE: page numbers are displayed as part of headers,
1701 see variable `ps-print-headers'."
1703 :group
'ps-print-header
)
1705 (defcustom ps-spool-config
(if (memq system-type
1706 '(win32 w32 mswindows ms-dos windows-nt
))
1709 "*Specify who is responsable for setting duplex and page size switches.
1713 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
1714 Don't forget to set `ps-lpr-switches' to select duplex
1715 printing for your printer.
1717 `setpagedevice' duplex and page size are configured by ps-print using the
1718 setpagedevice PostScript operator.
1720 nil duplex and page size are configured by ps-print *not* using
1721 the setpagedevice PostScript operator.
1723 Any other value is treated as nil.
1725 WARNING: The setpagedevice PostScript operator affects ghostview utility when
1726 viewing file generated using landscape. Also on some printers,
1727 setpagedevice affects zebra stripes; on other printers, setpagedevice
1728 affects the left margin.
1729 Besides all that, if your printer does not have the paper size
1730 specified by setpagedevice, your printing will be aborted.
1731 So, if you need to use setpagedevice, set `ps-spool-config' to
1732 `setpagedevice', generate a test file and send it to your printer; if
1733 the printed file isn't ok, set `ps-spool-config' to nil."
1734 :type
'(choice :tag
"Spool Config"
1735 (const lpr-switches
) (const setpagedevice
)
1736 (other :tag
"nil" nil
))
1737 :group
'ps-print-header
)
1739 (defcustom ps-spool-duplex nil
; Not many people have duplex printers,
1740 ; so default to nil.
1741 "*Non-nil generates PostScript for a two-sided printer.
1742 For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
1743 blank pages as needed between print jobs so that the next buffer printed will
1744 start on the right page. Also, if headers are turned on, the headers will be
1745 reversed on duplex printers so that the page numbers fall to the left on
1746 even-numbered pages.
1748 See also `ps-spool-tumble'."
1750 :group
'ps-print-header
)
1752 (defcustom ps-spool-tumble nil
1753 "*Specify how the page images on opposite sides of a sheet are oriented.
1754 If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
1755 right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
1758 It has effect only when `ps-spool-duplex' is non-nil."
1760 :group
'ps-print-header
)
1764 (defcustom ps-font-info-database
1765 '((Courier ; the family key
1766 (fonts (normal .
"Courier")
1767 (bold .
"Courier-Bold")
1768 (italic .
"Courier-Oblique")
1769 (bold-italic .
"Courier-BoldOblique"))
1771 (line-height .
10.55)
1773 (avg-char-width .
6.0))
1774 (Helvetica ; the family key
1775 (fonts (normal .
"Helvetica")
1776 (bold .
"Helvetica-Bold")
1777 (italic .
"Helvetica-Oblique")
1778 (bold-italic .
"Helvetica-BoldOblique"))
1780 (line-height .
11.56)
1781 (space-width .
2.78)
1782 (avg-char-width .
5.09243))
1784 (fonts (normal .
"Times-Roman")
1785 (bold .
"Times-Bold")
1786 (italic .
"Times-Italic")
1787 (bold-italic .
"Times-BoldItalic"))
1789 (line-height .
11.0)
1791 (avg-char-width .
4.71432))
1793 (fonts (normal .
"Palatino-Roman")
1794 (bold .
"Palatino-Bold")
1795 (italic .
"Palatino-Italic")
1796 (bold-italic .
"Palatino-BoldItalic"))
1798 (line-height .
12.1)
1800 (avg-char-width .
5.08676))
1802 (fonts (normal .
"Helvetica-Narrow")
1803 (bold .
"Helvetica-Narrow-Bold")
1804 (italic .
"Helvetica-Narrow-Oblique")
1805 (bold-italic .
"Helvetica-Narrow-BoldOblique"))
1807 (line-height .
11.56)
1808 (space-width .
2.2796)
1809 (avg-char-width .
4.17579))
1811 (fonts (normal .
"NewCenturySchlbk-Roman")
1812 (bold .
"NewCenturySchlbk-Bold")
1813 (italic .
"NewCenturySchlbk-Italic")
1814 (bold-italic .
"NewCenturySchlbk-BoldItalic"))
1816 (line-height .
12.15)
1817 (space-width .
2.78)
1818 (avg-char-width .
5.31162))
1819 ;; got no bold for the next ones
1821 (fonts (normal .
"AvantGarde-Book")
1822 (italic .
"AvantGarde-BookOblique"))
1824 (line-height .
11.77)
1825 (space-width .
2.77)
1826 (avg-char-width .
5.45189))
1828 (fonts (normal .
"AvantGarde-Demi")
1829 (italic .
"AvantGarde-DemiOblique"))
1831 (line-height .
12.72)
1833 (avg-char-width .
5.51351))
1835 (fonts (normal .
"Bookman-Demi")
1836 (italic .
"Bookman-DemiItalic"))
1838 (line-height .
11.77)
1840 (avg-char-width .
6.05946))
1842 (fonts (normal .
"Bookman-Light")
1843 (italic .
"Bookman-LightItalic"))
1845 (line-height .
11.79)
1847 (avg-char-width .
5.67027))
1848 ;; got no bold and no italic for the next ones
1850 (fonts (normal .
"Symbol"))
1852 (line-height .
13.03)
1854 (avg-char-width .
3.24324))
1856 (fonts (normal .
"Zapf-Dingbats"))
1858 (line-height .
9.63)
1859 (space-width .
2.78)
1860 (avg-char-width .
2.78))
1861 (Zapf-Chancery-MediumItalic
1862 (fonts (normal .
"Zapf-Chancery-MediumItalic"))
1864 (line-height .
11.45)
1866 (avg-char-width .
4.10811))
1868 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1869 reference size, line height, space width, average character width.
1870 To get the info for another specific font (say Helvetica), do the following:
1871 - create a new buffer
1872 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
1873 - open this file and delete the leading `%' (which is the PostScript
1874 comment character) from the line
1875 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
1877 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
1878 - add the values to `ps-font-info-database'.
1879 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
1880 :type
'(repeat (list :tag
"Font Definition"
1881 (symbol :tag
"Font Family")
1883 (const :format
"" fonts
)
1884 (repeat :tag
"Faces"
1885 (cons (choice (const normal
)
1889 (symbol :tag
"Face"))
1890 (string :tag
"Font Name"))))
1892 (const :format
"" size
)
1893 (number :tag
"Reference Size"))
1895 (const :format
"" line-height
)
1896 (number :tag
"Line Height"))
1898 (const :format
"" space-width
)
1899 (number :tag
"Space Width"))
1901 (const :format
"" avg-char-width
)
1902 (number :tag
"Average Character Width"))))
1903 :group
'ps-print-font
)
1905 (defcustom ps-font-family
'Courier
1906 "*Font family name for ordinary text, when generating PostScript."
1908 :group
'ps-print-font
)
1910 (defcustom ps-font-size
'(7 .
8.5)
1911 "*Font size, in points, for ordinary text, when generating PostScript."
1912 :type
'(choice (number :tag
"Text Size")
1913 (cons :tag
"Landscape/Portrait"
1914 (number :tag
"Landscape Text Size")
1915 (number :tag
"Portrait Text Size")))
1916 :group
'ps-print-font
)
1918 (defcustom ps-header-font-family
'Helvetica
1919 "*Font family name for text in the header, when generating PostScript."
1921 :group
'ps-print-font
)
1923 (defcustom ps-header-font-size
'(10 .
12)
1924 "*Font size, in points, for text in the header, when generating PostScript."
1925 :type
'(choice (number :tag
"Header Size")
1926 (cons :tag
"Landscape/Portrait"
1927 (number :tag
"Landscape Header Size")
1928 (number :tag
"Portrait Header Size")))
1929 :group
'ps-print-font
)
1931 (defcustom ps-header-title-font-size
'(12 .
14)
1932 "*Font size, in points, for the top line of text in header, in PostScript."
1933 :type
'(choice (number :tag
"Header Title Size")
1934 (cons :tag
"Landscape/Portrait"
1935 (number :tag
"Landscape Header Title Size")
1936 (number :tag
"Portrait Header Title Size")))
1937 :group
'ps-print-font
)
1941 ;; Printing color requires x-color-values.
1942 (defcustom ps-print-color-p
(or (fboundp 'x-color-values
) ; Emacs
1943 (fboundp 'color-instance-rgb-components
))
1945 "*Non-nil means print the buffer's text in color."
1947 :group
'ps-print-color
)
1949 (defcustom ps-default-fg
'(0.0
0.0 0.0)
1950 "*RGB values of the default foreground color. Defaults to black."
1951 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1952 :group
'ps-print-color
)
1954 (defcustom ps-default-bg
'(1.0
1.0 1.0)
1955 "*RGB values of the default background color. Defaults to white."
1956 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1957 :group
'ps-print-color
)
1959 (defcustom ps-auto-font-detect t
1960 "*Non-nil means automatically detect bold/italic face attributes.
1961 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
1962 and `ps-underlined-faces'."
1964 :group
'ps-print-font
)
1966 (defcustom ps-bold-faces
1967 (unless ps-print-color-p
1968 '(font-lock-function-name-face
1969 font-lock-builtin-face
1970 font-lock-variable-name-face
1971 font-lock-keyword-face
1972 font-lock-warning-face
))
1973 "*A list of the \(non-bold\) faces that should be printed in bold font.
1974 This applies to generating PostScript."
1975 :type
'(repeat face
)
1976 :group
'ps-print-face
)
1978 (defcustom ps-italic-faces
1979 (unless ps-print-color-p
1980 '(font-lock-variable-name-face
1982 font-lock-string-face
1983 font-lock-comment-face
1984 font-lock-warning-face
))
1985 "*A list of the \(non-italic\) faces that should be printed in italic font.
1986 This applies to generating PostScript."
1987 :type
'(repeat face
)
1988 :group
'ps-print-face
)
1990 (defcustom ps-underlined-faces
1991 (unless ps-print-color-p
1992 '(font-lock-function-name-face
1993 font-lock-constant-face
1994 font-lock-warning-face
))
1995 "*A list of the \(non-underlined\) faces that should be printed underlined.
1996 This applies to generating PostScript."
1997 :type
'(repeat face
)
1998 :group
'ps-print-face
)
2000 (defcustom ps-left-header
2001 (list 'ps-get-buffer-name
'ps-header-dirpart
)
2002 "*The items to display (each on a line) on the left part of the page header.
2003 This applies to generating PostScript.
2005 The value should be a list of strings and symbols, each representing an
2006 entry in the PostScript array HeaderLinesLeft.
2008 Strings are inserted unchanged into the array; those representing
2009 PostScript string literals should be delimited with PostScript string
2010 delimiters '(' and ')'.
2012 For symbols with bound functions, the function is called and should
2013 return a string to be inserted into the array. For symbols with bound
2014 values, the value should be a string to be inserted into the array.
2015 In either case, function or variable, the string value has PostScript
2016 string delimiters added to it."
2017 :type
'(repeat (choice string symbol
))
2018 :group
'ps-print-header
)
2020 (defcustom ps-right-header
2021 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy
'time-stamp-hh
:mm
:ss
)
2022 "*The items to display (each on a line) on the right part of the page header.
2023 This applies to generating PostScript.
2025 See the variable `ps-left-header' for a description of the format of
2027 :type
'(repeat (choice string symbol
))
2028 :group
'ps-print-header
)
2030 (defcustom ps-razzle-dazzle t
2031 "*Non-nil means report progress while formatting buffer."
2035 (defcustom ps-adobe-tag
"%!PS-Adobe-3.0\n"
2036 "*Contains the header line identifying the output as PostScript.
2037 By default, `ps-adobe-tag' contains the standard identifier. Some
2038 printers require slightly different versions of this line."
2042 (defcustom ps-build-face-reference t
2043 "*Non-nil means build the reference face lists.
2045 ps-print sets this value to nil after it builds its internal reference
2046 lists of bold and italic faces. By settings its value back to t, you
2047 can force ps-print to rebuild the lists the next time you invoke one
2048 of the ...-with-faces commands.
2050 You should set this value back to t after you change the attributes of
2051 any face, or create new faces. Most users shouldn't have to worry
2052 about its setting, though."
2054 :group
'ps-print-face
)
2056 (defcustom ps-always-build-face-reference nil
2057 "*Non-nil means always rebuild the reference face lists.
2059 If this variable is non-nil, ps-print will rebuild its internal
2060 reference lists of bold and italic faces *every* time one of the
2061 ...-with-faces commands is called. Most users shouldn't need to set this
2064 :group
'ps-print-face
)
2066 (defcustom ps-banner-page-when-duplexing nil
2067 "*Non-nil means the very first page is skipped.
2068 It's like the very first character of buffer (or region) is ^L (\\014)."
2070 :group
'ps-print-header
)
2072 (defcustom ps-postscript-code-directory data-directory
2073 "*Directory where it's located the PostScript prologue file used by ps-print.
2074 By default, this directory is the same as in the variable `data-directory'."
2079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2084 (defun ps-print-customize ()
2085 "Customization of ps-print group."
2087 (customize-group 'ps-print
))
2090 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2095 (defun ps-print-buffer (&optional filename
)
2096 "Generate and print a PostScript image of the buffer.
2098 Interactively, when you use a prefix argument (C-u), the command
2099 prompts the user for a file name, and saves the PostScript image
2100 in that file instead of sending it to the printer.
2102 Noninteractively, the argument FILENAME is treated as follows: if it
2103 is nil, send the image to the printer. If FILENAME is a string, save
2104 the PostScript image in a file with that name."
2105 (interactive (list (ps-print-preprint current-prefix-arg
)))
2106 (ps-print-without-faces (point-min) (point-max) filename
))
2110 (defun ps-print-buffer-with-faces (&optional filename
)
2111 "Generate and print a PostScript image of the buffer.
2112 Like `ps-print-buffer', but includes font, color, and underline
2113 information in the generated image. This command works only if you
2114 are using a window system, so it has a way to determine color values."
2115 (interactive (list (ps-print-preprint current-prefix-arg
)))
2116 (ps-print-with-faces (point-min) (point-max) filename
))
2120 (defun ps-print-region (from to
&optional filename
)
2121 "Generate and print a PostScript image of the region.
2122 Like `ps-print-buffer', but prints just the current region."
2123 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2124 (ps-print-without-faces from to filename t
))
2128 (defun ps-print-region-with-faces (from to
&optional filename
)
2129 "Generate and print a PostScript image of the region.
2130 Like `ps-print-region', but includes font, color, and underline
2131 information in the generated image. This command works only if you
2132 are using a window system, so it has a way to determine color values."
2133 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2134 (ps-print-with-faces from to filename t
))
2138 (defun ps-spool-buffer ()
2139 "Generate and spool a PostScript image of the buffer.
2140 Like `ps-print-buffer' except that the PostScript image is saved in a
2141 local buffer to be sent to the printer later.
2143 Use the command `ps-despool' to send the spooled images to the printer."
2145 (ps-spool-without-faces (point-min) (point-max)))
2149 (defun ps-spool-buffer-with-faces ()
2150 "Generate and spool a PostScript image of the buffer.
2151 Like `ps-spool-buffer', but includes font, color, and underline
2152 information in the generated image. This command works only if you
2153 are using a window system, so it has a way to determine color values.
2155 Use the command `ps-despool' to send the spooled images to the printer."
2157 (ps-spool-with-faces (point-min) (point-max)))
2161 (defun ps-spool-region (from to
)
2162 "Generate a PostScript image of the region and spool locally.
2163 Like `ps-spool-buffer', but spools just the current region.
2165 Use the command `ps-despool' to send the spooled images to the printer."
2167 (ps-spool-without-faces from to t
))
2171 (defun ps-spool-region-with-faces (from to
)
2172 "Generate a PostScript image of the region and spool locally.
2173 Like `ps-spool-region', but includes font, color, and underline
2174 information in the generated image. This command works only if you
2175 are using a window system, so it has a way to determine color values.
2177 Use the command `ps-despool' to send the spooled images to the printer."
2179 (ps-spool-with-faces from to t
))
2182 (defun ps-despool (&optional filename
)
2183 "Send the spooled PostScript to the printer.
2185 Interactively, when you use a prefix argument (C-u), the command
2186 prompts the user for a file name, and saves the spooled PostScript
2187 image in that file instead of sending it to the printer.
2189 Noninteractively, the argument FILENAME is treated as follows: if it
2190 is nil, send the image to the printer. If FILENAME is a string, save
2191 the PostScript image in a file with that name."
2192 (interactive (list (ps-print-preprint current-prefix-arg
)))
2193 (ps-do-despool filename
))
2196 (defun ps-line-lengths ()
2197 "Display the correspondence between a line length and a font size,
2198 using the current ps-print setup.
2199 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2201 (ps-line-lengths-internal))
2204 (defun ps-nb-pages-buffer (nb-lines)
2205 "Display number of pages to print this buffer, for various font heights.
2206 The table depends on the current ps-print setup."
2207 (interactive (list (count-lines (point-min) (point-max))))
2208 (ps-nb-pages nb-lines
))
2211 (defun ps-nb-pages-region (nb-lines)
2212 "Display number of pages to print the region, for various font heights.
2213 The table depends on the current ps-print setup."
2214 (interactive (list (count-lines (mark) (point))))
2215 (ps-nb-pages nb-lines
))
2219 "Return the current PostScript-generation setup."
2222 \(setq ps-print-color-p %s
2226 ps-print-region-function %s
2229 ps-landscape-mode %s
2230 ps-number-of-columns %s
2233 ps-zebra-stripe-height %s
2237 ps-print-control-characters %s
2239 ps-print-background-image %s
2241 ps-print-background-text %s
2243 ps-error-handler-message %s
2244 ps-user-defined-prologue %s
2245 ps-print-prologue-header %s
2253 ps-header-line-pad %s
2255 ps-print-only-one-header %s
2256 ps-print-header-frame %s
2262 ps-banner-page-when-duplexing %s
2269 ps-multibyte-buffer %s
2272 ps-header-font-family %s
2273 ps-header-font-size %s
2274 ps-header-title-font-size %s)
2278 (ps-print-quote ps-lpr-switches
)
2280 (ps-print-quote ps-print-region-function
)
2281 (ps-print-quote ps-paper-type
)
2283 ps-number-of-columns
2285 ps-zebra-stripe-height
2288 (ps-print-quote ps-print-control-characters
)
2289 (ps-print-quote ps-print-background-image
)
2290 (ps-print-quote ps-print-background-text
)
2291 (ps-print-quote ps-error-handler-message
)
2292 (ps-print-quote ps-user-defined-prologue
)
2293 (ps-print-quote ps-print-prologue-header
)
2302 ps-print-only-one-header
2303 ps-print-header-frame
2306 (ps-print-quote ps-spool-config
)
2309 ps-banner-page-when-duplexing
2313 (ps-print-quote ps-n-up-filling
)
2314 (ps-print-quote ps-multibyte-buffer
) ; see `ps-mule.el'
2315 (ps-print-quote ps-font-family
)
2316 (ps-print-quote ps-font-size
)
2317 (ps-print-quote ps-header-font-family
)
2318 (ps-print-quote ps-header-font-size
)
2319 (ps-print-quote ps-header-title-font-size
)))
2322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2323 ;; Utility functions and variables:
2326 (defun ps-print-quote (sym)
2329 ((or (symbolp sym
) (listp sym
))
2336 (defvar ps-print-emacs-type
2337 (cond ((string-match "XEmacs" emacs-version
) 'xemacs
)
2338 ((string-match "Lucid" emacs-version
) 'lucid
)
2339 ((string-match "Epoch" emacs-version
) 'epoch
)
2342 (if (or (eq ps-print-emacs-type
'lucid
)
2343 (eq ps-print-emacs-type
'xemacs
))
2344 (if (< emacs-minor-version
12)
2345 (setq ps-print-color-p nil
))
2346 (require 'faces
)) ; face-font, face-underline-p,
2349 ;; Return t if the device (which can be changed during an emacs session)
2350 ;; can handle colors.
2351 ;; This is function is not yet implemented for GNU emacs.
2352 (cond ((and (eq ps-print-emacs-type
'xemacs
)
2353 (>= emacs-minor-version
12)) ; xemacs
2354 (defun ps-color-device ()
2355 (eq (device-class) 'color
))
2359 (defun ps-color-device ()
2364 (require 'time-stamp
)
2367 (defun ps-prologue-file (filenumber)
2370 (or (find-file-noselect
2371 (format "%sps-prin%d.ps"
2372 ps-postscript-code-directory filenumber
)
2374 (error "ps-print PostScript prologue %d file was not found."
2379 (kill-buffer buffer
)))))
2382 (defvar ps-mark-code-directory nil
)
2384 (defvar ps-print-prologue-0
""
2385 "ps-print PostScript error handler.")
2387 (defvar ps-print-prologue-1
""
2388 "ps-print PostScript prologue begin.")
2390 (defvar ps-print-prologue-2
""
2391 "ps-print PostScript prologue end.")
2393 (defvar ps-print-duplex-feature
""
2394 "ps-print PostScript duplex feature.")
2396 ;; Start Editing Here:
2398 (defvar ps-source-buffer nil
)
2399 (defvar ps-spool-buffer-name
"*PostScript*")
2400 (defvar ps-spool-buffer nil
)
2402 (defvar ps-output-head nil
)
2403 (defvar ps-output-tail nil
)
2405 (defvar ps-page-postscript
0)
2406 (defvar ps-page-order
0)
2407 (defvar ps-page-count
0)
2408 (defvar ps-showline-count
1)
2410 (defvar ps-control-or-escape-regexp nil
)
2412 (defvar ps-background-pages nil
)
2413 (defvar ps-background-all-pages nil
)
2414 (defvar ps-background-text-count
0)
2415 (defvar ps-background-image-count
0)
2417 (defvar ps-current-font
0)
2418 (defvar ps-default-color
(and ps-print-color-p ps-default-fg
)) ; black
2419 (defvar ps-current-color ps-default-color
)
2420 (defvar ps-current-bg nil
)
2422 (defvar ps-razchunk
0)
2424 (defvar ps-color-p nil
)
2425 (defvar ps-color-format
2426 (if (eq ps-print-emacs-type
'emacs
)
2428 ;; Emacs understands the %f format; we'll use it to limit color RGB
2429 ;; values to three decimals to cut down some on the size of the
2430 ;; PostScript output.
2433 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2436 ;; These values determine how much print-height to deduct when headers
2437 ;; are turned on. This is a pretty clumsy way of handling it, but
2438 ;; it'll do for now.
2440 (defvar ps-header-pad
0
2441 "Vertical and horizontal space between the header frame and the text.
2442 This is in units of points (1/72 inch).")
2444 ;; Define accessors to the dimensions list.
2446 (defmacro ps-page-dimensions-get-width
(dims) `(nth 0 ,dims
))
2447 (defmacro ps-page-dimensions-get-height
(dims) `(nth 1 ,dims
))
2448 (defmacro ps-page-dimensions-get-media
(dims) `(nth 2 ,dims
))
2450 (defvar ps-landscape-page-height nil
)
2452 (defvar ps-print-width nil
)
2453 (defvar ps-print-height nil
)
2455 (defvar ps-height-remaining nil
)
2456 (defvar ps-width-remaining nil
)
2458 (defvar ps-print-color-scale nil
)
2460 (defvar ps-font-size-internal nil
)
2461 (defvar ps-header-font-size-internal nil
)
2462 (defvar ps-header-title-font-size-internal nil
)
2465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2466 ;; Internal Variables
2469 (defvar ps-print-face-extension-alist nil
2470 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2471 An element of this list has the following form:
2473 (FACE . [BITS FG BG])
2475 FACE is a symbol denoting a face name
2476 BITS is a bit vector, where each bit correspond
2477 to a feature (bold, underline, etc)
2478 (see documentation for `ps-print-face-map-alist')
2479 FG foreground color (string or nil)
2480 BG background color (string or nil)
2482 Don't change this list directly; instead,
2483 use `ps-extend-face' and `ps-extend-face-list'.
2484 See documentation for `ps-extend-face' for valid extension symbol.")
2487 (defvar ps-print-face-alist nil
2488 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2490 An element of this list has the same form as an element of
2491 `ps-print-face-extension-alist'.
2493 Don't change this list directly; this list is used by `ps-face-attributes',
2494 `ps-map-face' and `ps-build-reference-face-lists'.")
2497 (defconst ps-print-face-map-alist
2506 "Alist of all features and the corresponding bit mask.
2507 Each symbol correspond to one bit in a bit vector.")
2510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2515 (defun ps-extend-face-list (face-extension-list &optional merge-p
)
2516 "Extend face in `ps-print-face-extension-alist'.
2518 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2519 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2521 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2523 See `ps-extend-face' for documentation."
2524 (while face-extension-list
2525 (ps-extend-face (car face-extension-list
) merge-p
)
2526 (setq face-extension-list
(cdr face-extension-list
))))
2530 (defun ps-extend-face (face-extension &optional merge-p
)
2531 "Extend face in `ps-print-face-extension-alist'.
2533 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2534 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2536 The elements of FACE-EXTENSION list have the form:
2538 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2540 FACE-NAME is a face name symbol.
2542 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2543 foreground and background colors respectively.
2545 EXTENSION is one of the following symbols:
2546 bold - use bold font.
2547 italic - use italic font.
2548 underline - put a line under text.
2549 strikeout - like underline, but the line is in middle of text.
2550 overline - like underline, but the line is over the text.
2551 shadow - text will have a shadow.
2552 box - text will be surrounded by a box.
2553 outline - print characters as hollow outlines.
2555 If EXTENSION is any other symbol, it is ignored."
2556 (let* ((face-name (nth 0 face-extension
))
2557 (foreground (nth 1 face-extension
))
2558 (background (nth 2 face-extension
))
2559 (ps-face (cdr (assq face-name ps-print-face-extension-alist
)))
2560 (face-vector (or ps-face
(vector 0 nil nil
)))
2561 (face-bit (ps-extension-bit face-extension
)))
2563 (aset face-vector
0 (if merge-p
2564 (logior (aref face-vector
0) face-bit
)
2566 (and foreground
(stringp foreground
) (aset face-vector
1 foreground
))
2567 (and background
(stringp background
) (aset face-vector
2 background
))
2568 ;; if face does not exist, insert it
2570 (setq ps-print-face-extension-alist
2571 (cons (cons face-name face-vector
)
2572 ps-print-face-extension-alist
)))))
2575 (defun ps-extension-bit (face-extension)
2577 ;; map valid symbol extension to bit vector
2578 (setq face-extension
(cdr (cdr face-extension
)))
2579 (while (setq face-extension
(cdr face-extension
))
2580 (setq face-bit
(logior face-bit
2581 (or (cdr (assq (car face-extension
)
2582 ps-print-face-map-alist
))
2587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2588 ;; Adapted from font-lock: (obsolete stuff)
2589 ;; Originally face attributes were specified via `font-lock-face-attributes'.
2590 ;; Users then changed the default face attributes by setting that variable.
2591 ;; However, we try and be back-compatible and respect its value if set except
2592 ;; for faces where M-x customize has been used to save changes for the face.
2595 (defun ps-font-lock-face-attributes ()
2596 (and (boundp 'font-lock-mode
) (symbol-value 'font-lock-mode
)
2597 (boundp 'font-lock-face-attributes
)
2598 (let ((face-attributes font-lock-face-attributes
))
2599 (while face-attributes
2600 (let* ((face-attribute
2601 (car (prog1 face-attributes
2602 (setq face-attributes
(cdr face-attributes
)))))
2603 (face (car face-attribute
)))
2604 ;; Rustle up a `defface' SPEC from a
2605 ;; `font-lock-face-attributes' entry.
2606 (unless (get face
'saved-face
)
2607 (let ((foreground (nth 1 face-attribute
))
2608 (background (nth 2 face-attribute
))
2609 (bold-p (nth 3 face-attribute
))
2610 (italic-p (nth 4 face-attribute
))
2611 (underline-p (nth 5 face-attribute
))
2614 (setq face-spec
(cons ':foreground
2615 (cons foreground face-spec
))))
2617 (setq face-spec
(cons ':background
2618 (cons background face-spec
))))
2620 (setq face-spec
(append '(:bold t
) face-spec
)))
2622 (setq face-spec
(append '(:italic t
) face-spec
)))
2624 (setq face-spec
(append '(:underline t
) face-spec
)))
2625 (custom-declare-face face
(list (list t face-spec
)) nil
)
2629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2630 ;; Internal functions and variables
2633 (make-local-hook 'ps-print-hook
)
2634 (make-local-hook 'ps-print-begin-sheet-hook
)
2635 (make-local-hook 'ps-print-begin-page-hook
)
2636 (make-local-hook 'ps-print-begin-column-hook
)
2639 (defun ps-print-without-faces (from to
&optional filename region-p
)
2640 (ps-spool-without-faces from to region-p
)
2641 (ps-do-despool filename
))
2644 (defun ps-spool-without-faces (from to
&optional region-p
)
2645 (run-hooks 'ps-print-hook
)
2646 (ps-printing-region region-p
)
2647 (ps-generate (current-buffer) from to
'ps-generate-postscript
))
2650 (defun ps-print-with-faces (from to
&optional filename region-p
)
2651 (ps-spool-with-faces from to region-p
)
2652 (ps-do-despool filename
))
2655 (defun ps-spool-with-faces (from to
&optional region-p
)
2656 (run-hooks 'ps-print-hook
)
2657 (ps-printing-region region-p
)
2658 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
))
2661 (defun ps-count-lines (from to
)
2662 (+ (count-lines from to
)
2665 (if (= (current-column) 0) 1 0))))
2668 (defvar ps-printing-region nil
2669 "Variable used to indicate if the region that ps-print is printing.
2670 It is a cons, the car of which is the line number where the region begins, and
2671 its cdr is the total number of lines in the buffer. Formatting functions can
2672 use this information to print the original line number (and not the number of
2673 lines printed), and to indicate in the header that the printout is of a partial
2677 (defvar ps-printing-region-p nil
2678 "Non-nil means ps-print is printing a region.")
2681 (defun ps-printing-region (region-p)
2682 (setq ps-printing-region-p region-p
2685 (ps-count-lines (point-min) (region-beginning))
2687 (ps-count-lines (point-min) (point-max)))))
2690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2691 ;; Internal functions
2694 (defsubst ps-font-alist
(font-sym)
2695 (get font-sym
'fonts
))
2697 (defun ps-font (font-sym font-type
)
2698 "Font family name for text of `font-type', when generating PostScript."
2699 (let* ((font-list (ps-font-alist font-sym
))
2700 (normal-font (cdr (assq 'normal font-list
))))
2701 (while (and font-list
(not (eq font-type
(car (car font-list
)))))
2702 (setq font-list
(cdr font-list
)))
2703 (or (cdr (car font-list
)) normal-font
)))
2705 (defun ps-fonts (font-sym)
2706 (mapcar 'cdr
(ps-font-alist font-sym
)))
2708 (defun ps-font-number (font-sym font-type
)
2709 (or (ps-alist-position font-type
(ps-font-alist font-sym
))
2712 (defsubst ps-line-height
(font-sym)
2713 "The height of a line, for generating PostScript.
2714 This is the value that ps-print uses to determine the height,
2715 y-dimension, of the lines of text it has printed, and thus affects the
2716 point at which page-breaks are placed.
2717 The line-height is *not* the same as the point size of the font."
2718 (get font-sym
'line-height
))
2720 (defsubst ps-title-line-height
(font-sym)
2721 "The height of a `title' line, for generating PostScript.
2722 This is the value that ps-print uses to determine the height,
2723 y-dimension, of the lines of text it has printed, and thus affects the
2724 point at which page-breaks are placed.
2725 The title-line-height is *not* the same as the point size of the font."
2726 (get font-sym
'title-line-height
))
2728 (defsubst ps-space-width
(font-sym)
2729 "The width of a space character, for generating PostScript.
2730 This value is used in expanding tab characters."
2731 (get font-sym
'space-width
))
2733 (defsubst ps-avg-char-width
(font-sym)
2734 "The average width, in points, of a character, for generating PostScript.
2735 This is the value that ps-print uses to determine the length,
2736 x-dimension, of the text it has printed, and thus affects the point at
2737 which long lines wrap around."
2738 (get font-sym
'avg-char-width
))
2740 (defun ps-line-lengths-internal ()
2741 "Display the correspondence between a line length and a font size,
2742 using the current ps-print setup.
2743 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2744 (let ((buf (get-buffer-create "*Line-lengths*"))
2745 (ifs ps-font-size-internal
) ; initial font size
2746 (icw (ps-avg-char-width 'ps-font-for-text
)) ; initial character width
2747 (print-width (progn (ps-get-page-dimensions)
2749 (ps-setup (ps-setup)) ; setup for the current buffer
2750 (fs-min 5) ; minimum font size
2751 cw-min
; minimum character width
2752 nb-cpl-max
; maximum nb of characters per line
2753 (fs-max 14) ; maximum font size
2754 cw-max
; maximum character width
2755 nb-cpl-min
; minimum nb of characters per line
2756 fs
; current font size
2757 cw
; current character width
2758 nb-cpl
; current nb of characters per line
2760 (setq cw-min
(/ (* icw fs-min
) ifs
)
2761 nb-cpl-max
(floor (/ print-width cw-min
))
2762 cw-max
(/ (* icw fs-max
) ifs
)
2763 nb-cpl-min
(floor (/ print-width cw-max
))
2766 (goto-char (point-max))
2767 (or (bolp) (insert "\n"))
2769 "nb char per line / font size\n")
2770 (while (<= nb-cpl nb-cpl-max
)
2771 (setq cw
(/ print-width
(float nb-cpl
))
2772 fs
(/ (* ifs cw
) icw
))
2773 (insert (format "%3s %s\n" nb-cpl fs
))
2774 (setq nb-cpl
(1+ nb-cpl
)))
2776 (display-buffer buf
'not-this-window
)))
2778 (defun ps-nb-pages (nb-lines)
2779 "Display correspondence between font size and the number of pages.
2780 The correspondence is based on having NB-LINES lines of text,
2781 and on the current ps-print setup."
2782 (let ((buf (get-buffer-create "*Nb-Pages*"))
2783 (ifs ps-font-size-internal
) ; initial font size
2784 (ilh (ps-line-height 'ps-font-for-text
)) ; initial line height
2785 (page-height (progn (ps-get-page-dimensions)
2787 (ps-setup (ps-setup)) ; setup for the current buffer
2788 (fs-min 4) ; minimum font size
2789 lh-min
; minimum line height
2790 nb-lpp-max
; maximum nb of lines per page
2791 nb-page-min
; minimum nb of pages
2792 (fs-max 14) ; maximum font size
2793 lh-max
; maximum line height
2794 nb-lpp-min
; minimum nb of lines per page
2795 nb-page-max
; maximum nb of pages
2796 fs
; current font size
2797 lh
; current line height
2798 nb-lpp
; current nb of lines per page
2799 nb-page
; current nb of pages
2801 (setq lh-min
(/ (* ilh fs-min
) ifs
)
2802 nb-lpp-max
(floor (/ page-height lh-min
))
2803 nb-page-min
(ceiling (/ (float nb-lines
) nb-lpp-max
))
2804 lh-max
(/ (* ilh fs-max
) ifs
)
2805 nb-lpp-min
(floor (/ page-height lh-max
))
2806 nb-page-max
(ceiling (/ (float nb-lines
) nb-lpp-min
))
2807 nb-page nb-page-min
)
2809 (goto-char (point-max))
2810 (or (bolp) (insert "\n"))
2812 (format "%d lines\n" nb-lines
)
2813 "nb page / font size\n")
2814 (while (<= nb-page nb-page-max
)
2815 (setq nb-lpp
(ceiling (/ nb-lines
(float nb-page
)))
2816 lh
(/ page-height nb-lpp
)
2817 fs
(/ (* ifs lh
) ilh
))
2818 (insert (format "%s %s\n" nb-page fs
))
2819 (setq nb-page
(1+ nb-page
)))
2821 (display-buffer buf
'not-this-window
)))
2823 ;; macros used in `ps-select-font'
2824 (defmacro ps-lookup
(key) `(cdr (assq ,key font-entry
)))
2825 (defmacro ps-size-scale
(key) `(/ (* (ps-lookup ,key
) font-size
) size
))
2827 (defun ps-select-font (font-family sym font-size title-font-size
)
2828 (let ((font-entry (cdr (assq font-family ps-font-info-database
))))
2830 (error "Don't have data to scale font %s. Known fonts families are %s"
2832 (mapcar 'car ps-font-info-database
)))
2833 (let ((size (ps-lookup 'size
)))
2834 (put sym
'fonts
(ps-lookup 'fonts
))
2835 (put sym
'space-width
(ps-size-scale 'space-width
))
2836 (put sym
'avg-char-width
(ps-size-scale 'avg-char-width
))
2837 (put sym
'line-height
(ps-size-scale 'line-height
))
2838 (put sym
'title-line-height
2839 (/ (* (ps-lookup 'line-height
) title-font-size
) size
)))))
2841 (defun ps-get-page-dimensions ()
2842 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
2843 page-width page-height
)
2845 ((null page-dimensions
)
2846 (error "`ps-paper-type' must be one of:\n%s"
2847 (mapcar 'car ps-page-dimensions-database
)))
2848 ((< ps-number-of-columns
1)
2849 (error "The number of columns %d should be positive"
2850 ps-number-of-columns
)))
2852 (ps-select-font ps-font-family
'ps-font-for-text
2853 ps-font-size-internal ps-font-size-internal
)
2854 (ps-select-font ps-header-font-family
'ps-font-for-header
2855 ps-header-font-size-internal
2856 ps-header-title-font-size-internal
)
2858 (setq page-width
(ps-page-dimensions-get-width page-dimensions
)
2859 page-height
(ps-page-dimensions-get-height page-dimensions
))
2862 (if ps-landscape-mode
2863 ;; exchange width and height
2864 (setq page-width
(prog1 page-height
(setq page-height page-width
))))
2866 ;; It is used to get the lower right corner (only in landscape mode)
2867 (setq ps-landscape-page-height page-height
)
2869 ;; | lm | text | ic | text | ic | text | rm |
2870 ;; page-width == lm + n * pw + (n - 1) * ic + rm
2871 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
2872 (setq ps-print-width
(/ (- page-width
2873 ps-left-margin ps-right-margin
2874 (* (1- ps-number-of-columns
) ps-inter-column
))
2875 ps-number-of-columns
))
2876 (if (<= ps-print-width
0)
2877 (error "Bad horizontal layout:
2879 ps-left-margin == %s
2880 ps-right-margin == %s
2881 ps-inter-column == %s
2882 ps-number-of-columns == %s
2883 | lm | text | ic | text | ic | text | rm |
2884 page-width == lm + n * print-width + (n - 1) * ic + rm
2885 => print-width == %d !"
2890 ps-number-of-columns
2893 (setq ps-print-height
2894 (- page-height ps-bottom-margin ps-top-margin
))
2895 (if (<= ps-print-height
0)
2896 (error "Bad vertical layout:
2898 ps-bottom-margin == %s
2899 page-height == bm + print-height + tm
2900 => print-height == %d !"
2904 ;; If headers are turned on, deduct the height of the header from
2905 ;; the print height.
2907 (setq ps-header-pad
(* ps-header-line-pad
2908 (ps-title-line-height 'ps-font-for-header
))
2909 ps-print-height
(- ps-print-height
2912 (ps-title-line-height 'ps-font-for-header
)
2913 (* (ps-line-height 'ps-font-for-header
)
2914 (1- ps-header-lines
))
2916 (if (<= ps-print-height
0)
2917 (error "Bad vertical layout:
2919 ps-bottom-margin == %s
2920 ps-header-offset == %s
2923 page-height == bm + print-height + tm - ho - hh
2924 => print-height == %d !"
2930 (ps-title-line-height 'ps-font-for-header
)
2931 (* (ps-line-height 'ps-font-for-header
)
2932 (1- ps-header-lines
))
2936 (defun ps-print-preprint (&optional filename
)
2938 (or (numberp filename
)
2940 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
2943 (prompt (format "Save PostScript to file: (default %s) " name
))
2944 (res (read-file-name prompt default-directory name nil
)))
2945 (while (cond ((not (file-writable-p res
))
2947 (setq prompt
"is unwritable"))
2948 ((file-exists-p res
)
2949 (setq prompt
"exists")
2950 (not (y-or-n-p (format "File `%s' exists; overwrite? "
2953 (setq res
(read-file-name
2954 (format "File %s; save PostScript to file: " prompt
)
2955 (file-name-directory res
) nil nil
2956 (file-name-nondirectory res
))))
2957 (if (file-directory-p res
)
2958 (expand-file-name name
(file-name-as-directory res
))
2961 ;; The following functions implement a simple list-buffering scheme so
2962 ;; that ps-print doesn't have to repeatedly switch between buffers
2963 ;; while spooling. The functions `ps-output' and `ps-output-string' build
2964 ;; up the lists; the function `ps-flush-output' takes the lists and
2965 ;; insert its contents into the spool buffer (*PostScript*).
2967 (defvar ps-string-escape-codes
2968 (let ((table (make-vector 256 nil
))
2970 ;; control characters
2971 (while (<= char ?
\037)
2972 (aset table char
(format "\\%03o" char
))
2973 (setq char
(1+ char
)))
2974 ;; printable characters
2975 (while (< char ?
\177)
2976 (aset table char
(format "%c" char
))
2977 (setq char
(1+ char
)))
2978 ;; DEL and 8-bit characters
2979 (while (<= char ?
\377)
2980 (aset table char
(format "\\%o" char
))
2981 (setq char
(1+ char
)))
2982 ;; Override ASCII formatting characters with named escape code:
2983 (aset table ?
\n "\\n") ; [NL] linefeed
2984 (aset table ?
\r "\\r") ; [CR] carriage return
2985 (aset table ?
\t "\\t") ; [HT] horizontal tab
2986 (aset table ?
\b "\\b") ; [BS] backspace
2987 (aset table ?
\f "\\f") ; [NP] form feed
2988 ;; Escape PostScript escape and string delimiter characters:
2989 (aset table ?
\\ "\\\\")
2990 (aset table ?\
( "\\(")
2991 (aset table ?\
) "\\)")
2993 "Vector used to map characters to PostScript string escape codes.")
2995 (defun ps-output-string-prim (string)
2996 (insert "(") ;insert start-string delimiter
2997 (save-excursion ;insert string
2998 (insert (string-as-unibyte string
)))
2999 ;; Find and quote special characters as necessary for PS
3000 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
3001 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
3002 (let ((special (following-char)))
3004 (insert (aref ps-string-escape-codes special
))))
3005 (goto-char (point-max))
3006 (insert ")")) ;insert end-string delimiter
3008 (defun ps-init-output-queue ()
3009 (setq ps-output-head
'("")
3010 ps-output-tail ps-output-head
))
3012 (defun ps-output (&rest args
)
3013 (setcdr ps-output-tail args
)
3014 (while (cdr ps-output-tail
)
3015 (setq ps-output-tail
(cdr ps-output-tail
))))
3017 (defun ps-output-string (string)
3018 (ps-output t string
))
3020 (defun ps-output-list (the-list)
3021 (mapcar 'ps-output the-list
))
3023 ;; Output strings in the list ARGS in the PostScript prologue part.
3024 (defun ps-output-prologue (args)
3025 (ps-output 'prologue
(if (stringp args
) (list args
) args
)))
3027 (defun ps-flush-output ()
3029 (set-buffer ps-spool-buffer
)
3030 (goto-char (point-max))
3031 (while ps-output-head
3032 (let ((it (car ps-output-head
)))
3035 (setq ps-output-head
(cdr ps-output-head
))
3036 (ps-output-string-prim (car ps-output-head
)))
3038 (setq ps-output-head
(cdr ps-output-head
))
3040 (search-backward "\nBeginDoc")
3042 (apply 'insert
(car ps-output-head
))))
3045 (setq ps-output-head
(cdr ps-output-head
))))
3046 (ps-init-output-queue))
3048 (defun ps-insert-file (fname)
3050 ;; Check to see that the file exists and is readable; if not, throw
3052 (or (file-readable-p fname
)
3053 (error "Could not read file `%s'" fname
))
3055 (set-buffer ps-spool-buffer
)
3056 (goto-char (point-max))
3057 (insert-file fname
)))
3059 ;; These functions insert the arrays that define the contents of the
3062 (defun ps-generate-header-line (fonttag &optional content
)
3063 (ps-output " [ " fonttag
" ")
3065 ;; Literal strings should be output as is -- the string must
3066 ;; contain its own PS string delimiters, '(' and ')', if necessary.
3068 (ps-output content
))
3070 ;; Functions are called -- they should return strings; they will be
3071 ;; inserted as strings and the PS string delimiters added.
3072 ((and (symbolp content
) (fboundp content
))
3073 (ps-output-string (funcall content
)))
3075 ;; Variables will have their contents inserted. They should
3076 ;; contain strings, and will be inserted as strings.
3077 ((and (symbolp content
) (boundp content
))
3078 (ps-output-string (symbol-value content
)))
3080 ;; Anything else will get turned into an empty string.
3082 (ps-output-string "")))
3085 (defun ps-generate-header (name contents
)
3086 (ps-output "/" name
" [\n")
3087 (if (> ps-header-lines
0)
3089 (ps-generate-header-line "/h0" (car contents
))
3090 (while (and (< count ps-header-lines
)
3091 (setq contents
(cdr contents
)))
3092 (ps-generate-header-line "/h1" (car contents
))
3093 (setq count
(1+ count
)))
3094 (ps-output "] def\n"))))
3097 (defun ps-output-boolean (name bool
&optional no-def
)
3098 (ps-output (format "/%s %s%s"
3099 name
(if bool
"true" "false") (if no-def
"\n" " def\n"))))
3102 (defun ps-background-pages (page-list func
)
3106 (let ((start (if (consp pages
) (car pages
) pages
))
3107 (end (if (consp pages
) (cdr pages
) pages
)))
3108 (and (integerp start
) (integerp end
) (<= start end
)
3109 (add-to-list 'ps-background-pages
(vector start end func
)))))
3111 (setq ps-background-all-pages
(cons func ps-background-all-pages
))))
3114 (defconst ps-boundingbox-re
3116 \\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3119 (defun ps-get-boundingbox ()
3121 (set-buffer ps-spool-buffer
)
3123 (if (re-search-forward ps-boundingbox-re nil t
)
3124 (vector (string-to-number ; lower x
3125 (buffer-substring (match-beginning 1) (match-end 1)))
3126 (string-to-number ; lower y
3127 (buffer-substring (match-beginning 2) (match-end 2)))
3128 (string-to-number ; upper x
3129 (buffer-substring (match-beginning 3) (match-end 3)))
3130 (string-to-number ; upper y
3131 (buffer-substring (match-beginning 4) (match-end 4))))
3132 (vector 0 0 0 0)))))
3135 ;; Emacs understands the %f format; we'll use it to limit color RGB values
3136 ;; to three decimals to cut down some on the size of the PostScript output.
3137 ;; Lucid emacsen will have to make do with %s (princ) for floats.
3139 (defvar ps-float-format
(if (eq ps-print-emacs-type
'emacs
)
3141 "%s ")) ; Lucid emacsen
3144 (defun ps-float-format (value &optional default
)
3145 (let ((literal (or value default
)))
3147 (format (if (numberp literal
)
3154 (defun ps-background-text ()
3157 (setq ps-background-text-count
(1+ ps-background-text-count
))
3158 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count
))
3159 (ps-output-string (nth 0 text
)) ; text
3162 (ps-float-format (nth 4 text
) 200.0) ; font size
3163 (format "/%s " (or (nth 3 text
) "Times-Roman")) ; font name
3164 (ps-float-format (nth 6 text
)
3165 "PrintHeight PrintPageWidth atan") ; rotation
3166 (ps-float-format (nth 5 text
) 0.85) ; gray
3167 (ps-float-format (nth 1 text
) "0") ; x position
3168 (ps-float-format (nth 2 text
) "BottomMargin") ; y position
3169 "\nShowBackText} def\n")
3170 (ps-background-pages (nthcdr 7 text
) ; page list
3171 (format "ShowBackText-%d\n"
3172 ps-background-text-count
)))
3173 ps-print-background-text
))
3176 (defun ps-background-image ()
3179 (let ((image-file (expand-file-name (nth 0 image
))))
3180 (when (file-readable-p image-file
)
3181 (setq ps-background-image-count
(1+ ps-background-image-count
))
3183 (format "/ShowBackImage-%d {\n--back-- "
3184 ps-background-image-count
)
3185 (ps-float-format (nth 5 image
) 0.0) ; rotation
3186 (ps-float-format (nth 3 image
) 1.0) ; x scale
3187 (ps-float-format (nth 4 image
) 1.0) ; y scale
3188 (ps-float-format (nth 1 image
) ; x position
3189 "PrintPageWidth 2 div")
3190 (ps-float-format (nth 2 image
) ; y position
3191 "PrintHeight 2 div BottomMargin add")
3192 "\nBeginBackImage\n")
3193 (ps-insert-file image-file
)
3194 ;; coordinate adjustment to centralize image
3195 ;; around x and y position
3196 (let ((box (ps-get-boundingbox)))
3198 (set-buffer ps-spool-buffer
)
3200 (if (re-search-backward "^--back--" nil t
)
3204 (- (+ (/ (- (aref box
2) (aref box
0)) 2.0)
3207 (- (+ (/ (- (aref box
3) (aref box
1)) 2.0)
3210 (ps-output "\nEndBackImage} def\n")
3211 (ps-background-pages (nthcdr 6 image
) ; page list
3212 (format "ShowBackImage-%d\n"
3213 ps-background-image-count
)))))
3214 ps-print-background-image
))
3217 (defun ps-background (page-number)
3218 (let (has-local-background)
3219 (mapcar #'(lambda (range)
3220 (and (<= (aref range
0) page-number
)
3221 (<= page-number
(aref range
1))
3222 (if has-local-background
3223 (ps-output (aref range
2))
3224 (setq has-local-background t
)
3225 (ps-output "/printLocalBackground {\n"
3227 ps-background-pages
)
3228 (and has-local-background
(ps-output "} def\n"))))
3231 ;; Return a list of the distinct elements of LIST.
3232 ;; Elements are compared with `equal'.
3233 (defun ps-remove-duplicates (list)
3234 (let (new (tail list
))
3236 (or (member (car tail
) new
)
3237 (setq new
(cons (car tail
) new
)))
3238 (setq tail
(cdr tail
)))
3242 ;; Find the first occurrence of ITEM in LIST.
3243 ;; Return the index of the matching item, or nil if not found.
3244 ;; Elements are compared with `eq'.
3245 (defun ps-alist-position (item list
)
3246 (let ((tail list
) (index 0) found
)
3248 (if (setq found
(eq (car (car tail
)) item
))
3250 (setq index
(1+ index
)
3255 (defconst ps-n-up-database
3392 ;; Ledger paper size is a special case, it is the only paper size where the
3393 ;; normal size is landscaped, that is, the height is smaller than width.
3394 ;; So, we use the special value `pag' in the `landscape' field.
3538 "Alist which is the page matrix database used for N-up printing.
3540 Each element has the following form:
3543 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
3547 PAGE is the page size used (see `ps-paper-type').
3548 MAX is the maximum elements of this page matrix.
3549 LANDSCAPE specifies if page matrix is landscaped, has the following valid
3551 nil the sheet is in portrait mode.
3552 t the sheet is in landscape mode.
3553 pag the sheet is in portrait mode and page is in landscape mode.
3554 LINES is the number of lines of page matrix.
3555 COLUMNS is the number of columns of page matrix.
3556 COL-MISSING is the number of columns missing to fill the sheet.")
3559 (defmacro ps-n-up-landscape
(mat) `(nth 1 ,mat
))
3560 (defmacro ps-n-up-lines
(mat) `(nth 2 ,mat
))
3561 (defmacro ps-n-up-columns
(mat) `(nth 3 ,mat
))
3562 (defmacro ps-n-up-missing
(mat) `(nth 4 ,mat
))
3565 (defun ps-n-up-printing ()
3566 ;; force `ps-n-up-printing' be in range 1 to 100.
3567 (setq ps-n-up-printing
(max (min ps-n-up-printing
100) 1))
3568 ;; find suitable page matrix for a given `ps-paper-type'.
3569 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database
))))
3571 (while (> ps-n-up-printing
(caar the-list
))
3572 (setq the-list
(cdr the-list
))))
3576 (defconst ps-n-up-filling-database
3578 "PageWidth" ; N-Up-XColumn
3580 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3581 "LandscapePageHeight neg" ; N-Up-YLine
3582 "N-Up-Lines" ; N-Up-Repeat
3583 "N-Up-Columns" ; N-Up-End
3587 "PageWidth" ; N-Up-XColumn
3589 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3590 "LandscapePageHeight" ; N-Up-YLine
3591 "N-Up-Lines" ; N-Up-Repeat
3592 "N-Up-Columns" ; N-Up-End
3594 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3596 "PageWidth neg" ; N-Up-XColumn
3598 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3599 "LandscapePageHeight neg" ; N-Up-YLine
3600 "N-Up-Lines" ; N-Up-Repeat
3601 "N-Up-Columns" ; N-Up-End
3602 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3605 "PageWidth neg" ; N-Up-XColumn
3607 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3608 "LandscapePageHeight" ; N-Up-YLine
3609 "N-Up-Lines" ; N-Up-Repeat
3610 "N-Up-Columns" ; N-Up-End
3611 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3612 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3615 "LandscapePageHeight neg" ; N-Up-YColumn
3616 "PageWidth" ; N-Up-XLine
3617 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3618 "N-Up-Columns" ; N-Up-Repeat
3619 "N-Up-Lines" ; N-Up-End
3624 "LandscapePageHeight" ; N-Up-YColumn
3625 "PageWidth" ; N-Up-XLine
3626 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3627 "N-Up-Columns" ; N-Up-Repeat
3628 "N-Up-Lines" ; N-Up-End
3630 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3633 "LandscapePageHeight neg" ; N-Up-YColumn
3634 "PageWidth neg" ; N-Up-XLine
3635 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3636 "N-Up-Columns" ; N-Up-Repeat
3637 "N-Up-Lines" ; N-Up-End
3638 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3642 "LandscapePageHeight" ; N-Up-YColumn
3643 "PageWidth neg" ; N-Up-XLine
3644 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3645 "N-Up-Columns" ; N-Up-Repeat
3646 "N-Up-Lines" ; N-Up-End
3647 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3648 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
3649 "Alist for n-up printing initializations.
3651 Each element has the following form:
3653 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
3656 KIND is a valid value of `ps-n-up-filling'.
3657 XCOL YCOL are the relative position for the next column.
3658 XLIN YLIN are the relative position for the beginning of next line.
3659 REPEAT is the number of repetions for external loop.
3660 END is the number of repetions for internal loop and also the number of pages in
3662 XSTART YSTART are the relative position for the first page in a sheet.")
3665 (defun ps-n-up-filling ()
3666 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database
)
3667 (assq 'left-top ps-n-up-filling-database
))))
3670 (defmacro ps-n-up-xcolumn
(init) `(nth 0 ,init
))
3671 (defmacro ps-n-up-ycolumn
(init) `(nth 1 ,init
))
3672 (defmacro ps-n-up-xline
(init) `(nth 2 ,init
))
3673 (defmacro ps-n-up-yline
(init) `(nth 3 ,init
))
3674 (defmacro ps-n-up-repeat
(init) `(nth 4 ,init
))
3675 (defmacro ps-n-up-end
(init) `(nth 5 ,init
))
3676 (defmacro ps-n-up-xstart
(init) `(nth 6 ,init
))
3677 (defmacro ps-n-up-ystart
(init) `(nth 7 ,init
))
3680 (defconst ps-error-handler-alist
3684 (paper-and-system .
3))
3685 "Alist for error handler message")
3688 (defun ps-begin-file ()
3689 (ps-get-page-dimensions)
3690 (setq ps-page-postscript
0
3692 ps-background-text-count
0
3693 ps-background-image-count
0
3694 ps-background-pages nil
3695 ps-background-all-pages nil
)
3697 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
3698 (tumble (if ps-landscape-mode
(not ps-spool-tumble
) ps-spool-tumble
))
3699 (n-up (ps-n-up-printing))
3700 (n-up-filling (ps-n-up-filling)))
3701 (and (> ps-n-up-printing
1) (setq tumble
(not tumble
)))
3704 "%%Title: " (buffer-name) ; Take job name from name of
3705 ; first buffer printed
3706 "\n%%Creator: " (user-full-name)
3707 " (using ps-print v" ps-print-version
3708 ")\n%%CreationDate: "
3709 (time-stamp-hh:mm
:ss
) " " (time-stamp-mon-dd-yyyy)
3711 (if ps-landscape-mode
"Landscape" "Portrait")
3712 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
3713 (mapconcat 'identity
3714 (ps-remove-duplicates
3715 (append (ps-fonts 'ps-font-for-text
)
3716 (list (ps-font 'ps-font-for-header
'normal
)
3717 (ps-font 'ps-font-for-header
'bold
))))
3719 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions
)
3720 (format " %d" (round (ps-page-dimensions-get-width dimensions
)))
3721 (format " %d" (round (ps-page-dimensions-get-height dimensions
)))
3722 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
3724 (format " duplex%s" (if tumble
"(tumble)\n" "\n"))
3727 (ps-insert-string ps-print-prologue-header
)
3729 (ps-output "%%EndComments\n\n%%BeginPrologue\n\n"
3730 "/gs_languagelevel /languagelevel where"
3731 "{pop languagelevel}{1}ifelse def\n"
3732 (format "/ErrorMessage %s def\n\n"
3733 (or (cdr (assoc ps-error-handler-message
3734 ps-error-handler-alist
))
3737 "\n%%BeginProcSet: UserDefinedPrologue\n\n")
3739 (ps-insert-string ps-user-defined-prologue
)
3741 (ps-output "\n%%EndProcSet\n\n")
3743 (ps-output-boolean "LandscapeMode "
3744 (or ps-landscape-mode
3745 (eq (ps-n-up-landscape n-up
) 'pag
)))
3746 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns
)
3748 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height
)
3749 (format "/PrintPageWidth %s def\n"
3750 (- (* (+ ps-print-width ps-inter-column
)
3751 ps-number-of-columns
)
3753 (format "/PrintWidth %s def\n" ps-print-width
)
3754 (format "/PrintHeight %s def\n" ps-print-height
)
3756 (format "/LeftMargin %s def\n" ps-left-margin
)
3757 (format "/RightMargin %s def\n" ps-right-margin
)
3758 (format "/InterColumn %s def\n" ps-inter-column
)
3760 (format "/BottomMargin %s def\n" ps-bottom-margin
)
3761 (format "/TopMargin %s def\n" ps-top-margin
) ; not used
3762 (format "/HeaderOffset %s def\n" ps-header-offset
)
3763 (format "/HeaderPad %s def\n" ps-header-pad
))
3765 (ps-output-boolean "PrintHeader " ps-print-header
)
3766 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header
)
3767 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame
)
3768 (ps-output-boolean "ShowNofN " ps-show-n-of-n
)
3769 (ps-output-boolean "DuplexValue " ps-spool-duplex
)
3770 (ps-output-boolean "TumbleValue " tumble
)
3772 (let ((line-height (ps-line-height 'ps-font-for-text
)))
3773 (ps-output (format "/LineHeight %s def\n" line-height
)
3774 (format "/LinesPerColumn %d def\n"
3775 (round (/ (+ ps-print-height
3776 (* line-height
0.45))
3779 (ps-output-boolean "Zebra " ps-zebra-stripes
)
3780 (ps-output-boolean "PrintLineNumber " ps-line-number
)
3781 (ps-output (format "/ZebraHeight %d def\n" ps-zebra-stripe-height
)
3782 (format "/ZebraGray %s def\n" ps-zebra-gray
)
3783 "/UseSetpagedevice "
3784 (if (eq ps-spool-config
'setpagedevice
)
3785 "/setpagedevice where {pop true}{false}ifelse def\n"
3788 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
3789 (format "/N-Up %d def\n" ps-n-up-printing
))
3790 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up
) t
))
3791 (ps-output-boolean "N-Up-Border " ps-n-up-border-p
)
3792 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up
))
3793 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up
))
3794 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up
))
3795 (format "/N-Up-Margin %s" ps-n-up-margin
)
3796 " def\n/N-Up-Repeat "
3797 (if ps-landscape-mode
3798 (ps-n-up-end n-up-filling
)
3799 (ps-n-up-repeat n-up-filling
))
3801 (if ps-landscape-mode
3802 (ps-n-up-repeat n-up-filling
)
3803 (ps-n-up-end n-up-filling
))
3804 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling
)
3805 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling
)
3806 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling
)
3807 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling
)
3808 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling
)
3809 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling
) " def\n")
3811 (ps-background-text)
3812 (ps-background-image)
3813 (setq ps-background-all-pages
(nreverse ps-background-all-pages
)
3814 ps-background-pages
(nreverse ps-background-pages
))
3816 (ps-output "\n" ps-print-prologue-1
)
3818 (ps-output "\n/printGlobalBackground {\n")
3819 (ps-output-list ps-background-all-pages
)
3820 (ps-output "} def\n/printLocalBackground {\n} def\n")
3823 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
3824 ps-header-title-font-size-internal
3825 (ps-font 'ps-font-for-header
'bold
))
3826 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
3827 ps-header-font-size-internal
3828 (ps-font 'ps-font-for-header
'normal
)))
3830 (ps-output "\n" ps-print-prologue-2
"\n")
3833 (let ((font (ps-font-alist 'ps-font-for-text
))
3836 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
3838 ps-font-size-internal
3839 (ps-font 'ps-font-for-text
(car (car font
)))))
3840 (setq font
(cdr font
)
3843 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database
))))
3844 (ps-output (format "/SpaceWidthRatio %f def\n"
3845 (/ (ps-lookup 'space-width
) (ps-lookup 'size
)))))
3847 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
3848 (unless (eq ps-spool-config
'lpr-switches
)
3849 (ps-output "\n%%BeginFeature: *Duplex "
3850 (ps-boolean-capitalized ps-spool-duplex
)
3852 (ps-boolean-capitalized tumble
)
3854 ps-print-duplex-feature
3855 "\n%%EndFeature\n")))
3856 (ps-output "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n")
3857 (and ps-banner-page-when-duplexing
3858 (ps-output "\n%%Page: 0 0\nsave showpage restore\n")))
3861 (defun ps-insert-string (prologue)
3862 (let ((str (if (functionp prologue
)
3869 (defun ps-boolean-capitalized (bool)
3870 (if bool
"True" "False"))
3873 (defun ps-header-dirpart ()
3874 (let ((fname (buffer-file-name)))
3876 (if (string-equal (buffer-name) (file-name-nondirectory fname
))
3877 (abbreviate-file-name (file-name-directory fname
))
3882 (defun ps-get-buffer-name ()
3884 ;; Indulge Jim this little easter egg:
3885 ((string= (buffer-name) "ps-print.el")
3886 "Hey, Cool! It's ps-print.el!!!")
3887 ;; Indulge Jack this other little easter egg:
3888 ((string= (buffer-name) "sokoban.el")
3889 "Super! C'est sokoban.el!")
3891 (and ps-printing-region-p
"Subset of: ")
3893 (and (buffer-modified-p) " (unsaved)")))))
3896 (defun ps-get-font-size (font-sym)
3897 (let ((font-size (symbol-value font-sym
)))
3898 (cond ((numberp font-size
)
3900 ((and (consp font-size
)
3901 (numberp (car font-size
))
3902 (numberp (cdr font-size
)))
3903 (if ps-landscape-mode
3907 (error "Invalid font size `%S' for `%S'" font-size font-sym
)))))
3910 (defun ps-begin-job ()
3911 (or (equal ps-mark-code-directory ps-postscript-code-directory
)
3912 (setq ps-print-prologue-0
(ps-prologue-file 0)
3913 ps-print-prologue-1
(ps-prologue-file 1)
3914 ps-print-prologue-2
(ps-prologue-file 2)
3915 ps-print-duplex-feature
(ps-prologue-file 3)
3916 ps-mark-code-directory ps-postscript-code-directory
))
3918 (set-buffer ps-spool-buffer
)
3919 (goto-char (point-max))
3920 (and (re-search-backward "^%%Trailer$" nil t
)
3921 (delete-region (match-beginning 0) (point-max))))
3922 (setq ps-showline-count
(car ps-printing-region
)
3924 ps-font-size-internal
(ps-get-font-size 'ps-font-size
)
3925 ps-header-font-size-internal
(ps-get-font-size 'ps-header-font-size
)
3926 ps-header-title-font-size-internal
3927 (ps-get-font-size 'ps-header-title-font-size
)
3928 ps-control-or-escape-regexp
3929 (cond ((eq ps-print-control-characters
'8-bit
)
3930 (string-as-unibyte "[\000-\037\177-\377]"))
3931 ((eq ps-print-control-characters
'control-8-bit
)
3932 (string-as-unibyte "[\000-\037\177-\237]"))
3933 ((eq ps-print-control-characters
'control
)
3937 (defmacro ps-page-number
()
3938 `(1+ (/ (1- ps-page-count
) ps-number-of-columns
)))
3940 (defun ps-end-file (needs-begin-file)
3942 ;; Back to the PS output buffer to set the last page n-up printing
3944 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing
))
3946 (set-buffer ps-spool-buffer
)
3947 (goto-char (point-max))
3948 (and (> pages-per-sheet
0)
3949 (re-search-backward "^[0-9]+ BeginSheet$" nil t
)
3950 (replace-match (format "%d BeginSheet" pages-per-sheet
) t
))))
3952 (and ps-spool-duplex
(= (mod ps-page-order
2) 1)
3954 ;; Set end of PostScript file
3955 (ps-output "EndSheet\n\n%%Trailer\n%%Pages: "
3957 (if (and needs-begin-file ps-banner-page-when-duplexing
)
3960 "\n\nEndDoc\n\n%%EOF\n"))
3963 (defun ps-next-page ()
3969 (defun ps-header-sheet ()
3970 ;; Print only when a new sheet begins.
3971 (setq ps-page-postscript
(1+ ps-page-postscript
)
3972 ps-page-order
(1+ ps-page-order
))
3973 (and (> ps-page-order
1)
3974 (ps-output "EndSheet\n"))
3975 (ps-output (format "\n%%%%Page: %d %d\n"
3976 ps-page-postscript ps-page-order
))
3977 (ps-output (format "%d BeginSheet\nBeginDSCPage\n" ps-n-up-printing
)))
3980 (defsubst ps-header-page
()
3981 ;; set total line and page number when printing has finished
3982 ;; (see `ps-generate')
3985 (zerop (mod ps-page-count ps-number-of-columns
))
3986 (setq ps-page-count
(1+ ps-page-count
)))
3988 (if (zerop (mod ps-page-postscript ps-n-up-printing
))
3989 ;; Print only when a new sheet begins.
3992 'ps-print-begin-sheet-hook
)
3993 ;; Print only when a new page begins.
3994 (setq ps-page-postscript
(1+ ps-page-postscript
))
3995 (ps-output "BeginDSCPage\n")
3996 'ps-print-begin-page-hook
)
3997 (ps-background ps-page-postscript
))
3998 ;; Print only when a new column begins.
3999 (ps-output "BeginDSCPage\n")
4000 'ps-print-begin-column-hook
)))
4002 (defun ps-begin-page ()
4003 (ps-get-page-dimensions)
4004 (setq ps-width-remaining ps-print-width
4005 ps-height-remaining ps-print-height
)
4009 (ps-output (format "/LineNumber %d def\n" ps-showline-count
)
4010 (format "/PageNumber %d def\n" (if ps-print-only-one-header
4014 (when ps-print-header
4015 (ps-generate-header "HeaderLinesLeft" ps-left-header
)
4016 (ps-generate-header "HeaderLinesRight" ps-right-header
)
4017 (ps-output (format "%d SetHeaderLines\n" ps-header-lines
)))
4019 (ps-output "BeginPage\n")
4020 (ps-set-font ps-current-font
)
4021 (ps-set-bg ps-current-bg
)
4022 (ps-set-color ps-current-color
)
4023 (ps-mule-begin-page))
4025 (defun ps-end-page ()
4026 (ps-output "EndPage\nEndDSCPage\n"))
4028 (defun ps-dummy-page ()
4029 (let ((ps-n-up-printing 0))
4031 (ps-output "/PrintHeader false def
4033 /PrintLineNumber false def
4037 (setq ps-page-postscript ps-n-up-printing
))
4039 (defun ps-next-line ()
4040 (setq ps-showline-count
(1+ ps-showline-count
))
4041 (let ((lh (ps-line-height 'ps-font-for-text
)))
4042 (if (< ps-height-remaining lh
)
4044 (setq ps-width-remaining ps-print-width
4045 ps-height-remaining
(- ps-height-remaining lh
))
4046 (ps-output "HL\n"))))
4048 (defun ps-continue-line ()
4049 (let ((lh (ps-line-height 'ps-font-for-text
)))
4050 (if (< ps-height-remaining lh
)
4052 (setq ps-width-remaining ps-print-width
4053 ps-height-remaining
(- ps-height-remaining lh
))
4054 (ps-output "SL\n"))))
4056 (defun ps-find-wrappoint (from to char-width
)
4057 (let ((avail (truncate (/ ps-width-remaining char-width
)))
4060 (cons to
(* todo char-width
))
4061 (cons (+ from avail
) ps-width-remaining
))))
4063 (defun ps-basic-plot-string (from to
&optional bg-color
)
4064 (let* ((wrappoint (ps-find-wrappoint from to
4065 (ps-avg-char-width 'ps-font-for-text
)))
4066 (to (car wrappoint
))
4067 (string (buffer-substring-no-properties from to
)))
4068 (ps-mule-prepare-ascii-font string
)
4069 (ps-output-string string
)
4073 (defun ps-basic-plot-whitespace (from to
&optional bg-color
)
4074 (let* ((wrappoint (ps-find-wrappoint from to
4075 (ps-space-width 'ps-font-for-text
)))
4076 (to (car wrappoint
)))
4077 (ps-output (format "%d W\n" (- to from
)))
4080 (defun ps-plot (plotfunc from to
&optional bg-color
)
4082 (let* ((wrappoint (funcall plotfunc from to bg-color
))
4083 (plotted-to (car wrappoint
))
4084 (plotted-width (cdr wrappoint
)))
4085 (setq from plotted-to
4086 ps-width-remaining
(- ps-width-remaining plotted-width
))
4088 (ps-continue-line))))
4089 (if ps-razzle-dazzle
4090 (let* ((q-todo (- (point-max) (point-min)))
4091 (q-done (- (point) (point-min)))
4092 (chunkfrac (/ q-todo
8))
4093 (chunksize (min chunkfrac
1000)))
4094 (if (> (- q-done ps-razchunk
) chunksize
)
4096 (setq ps-razchunk q-done
)
4097 (message "Formatting...%3d%%"
4099 (/ (* 100 q-done
) q-todo
)
4100 (/ q-done
(/ q-todo
100)))
4103 (defvar ps-last-font nil
)
4105 (defun ps-set-font (font)
4106 (setq ps-last-font
(format "f%d" (setq ps-current-font font
)))
4107 (ps-output (format "/%s F\n" ps-last-font
)))
4109 (defun ps-set-bg (color)
4110 (if (setq ps-current-bg color
)
4111 (ps-output (format ps-color-format
4112 (nth 0 color
) (nth 1 color
) (nth 2 color
))
4114 (ps-output "false BG\n")))
4116 (defun ps-set-color (color)
4117 (setq ps-current-color
(or color ps-default-fg
))
4118 (ps-output (format ps-color-format
4119 (nth 0 ps-current-color
)
4120 (nth 1 ps-current-color
) (nth 2 ps-current-color
))
4124 (defvar ps-current-effect
0)
4127 (defun ps-plot-region (from to font
&optional fg-color bg-color effects
)
4128 (if (not (equal font ps-current-font
))
4131 ;; Specify a foreground color only if one's specified and it's
4132 ;; different than the current.
4133 (if (not (equal fg-color ps-current-color
))
4134 (ps-set-color fg-color
))
4136 (if (not (equal bg-color ps-current-bg
))
4137 (ps-set-bg bg-color
))
4139 ;; Specify effects (underline, overline, box, etc)
4141 ((not (integerp effects
))
4142 (ps-output "0 EF\n")
4143 (setq ps-current-effect
0))
4144 ((/= effects ps-current-effect
)
4145 (ps-output (number-to-string effects
) " EF\n")
4146 (setq ps-current-effect effects
)))
4148 ;; Starting at the beginning of the specified region...
4152 ;; ...break the region up into chunks separated by tabs, linefeeds,
4153 ;; pagefeeds, control characters, and plot each chunk.
4155 (if (re-search-forward ps-control-or-escape-regexp to t
)
4156 ;; region with some control characters or some multi-byte characters
4157 (let* ((match-point (match-beginning 0))
4158 (match (char-after match-point
))
4159 (composition (find-composition from
(1+ match-point
))))
4161 (if (and (nth 2 composition
)
4162 (<= (car composition
) match-point
))
4164 (setq match-point
(car composition
)
4166 (goto-char (nth 1 composition
)))
4167 (setq composition nil
)))
4168 (when (< from match-point
)
4169 (ps-mule-set-ascii-font)
4170 (ps-plot 'ps-basic-plot-string from match-point bg-color
))
4172 ((= match ?
\t) ; tab
4173 (let ((linestart (line-beginning-position)))
4175 (setq from
(+ linestart
(current-column)))
4176 (when (re-search-forward "[ \t]+" to t
)
4177 (ps-mule-set-ascii-font)
4178 (ps-plot 'ps-basic-plot-whitespace
4179 from
(+ linestart
(current-column))
4182 ((= match ?
\n) ; newline
4185 ((= match ?
\f) ; form feed
4186 ;; do not skip page if previous character is NEWLINE and
4187 ;; it is a beginning of page.
4188 (or (and (= (char-after (1- match-point
)) ?
\n)
4189 (= ps-height-remaining ps-print-height
))
4192 (composition ; a composite sequence
4193 (ps-plot 'ps-mule-plot-composition match-point
(point) bg-color
))
4195 ; characters from ^@ to ^_ and
4196 ((> match
255) ; a multi-byte character
4197 (let* ((charset (char-charset match
))
4198 (composition (find-composition match-point to
))
4199 (stop (if (nth 2 composition
) (car composition
) to
)))
4200 (or (eq charset
'composition
)
4201 (while (and (< (point) stop
) (eq (charset-after) charset
))
4203 (ps-plot 'ps-mule-plot-string match-point
(point) bg-color
)))
4205 (t ; characters from 127 to 255
4206 (ps-control-character match
)))
4207 (setq from
(point)))
4208 ;; region without control characters nor multi-byte characters
4209 (ps-mule-set-ascii-font)
4210 (ps-plot 'ps-basic-plot-string from to bg-color
)
4213 (defvar ps-string-control-codes
4214 (let ((table (make-vector 256 nil
))
4216 ;; control character
4217 (while (<= char ?
\037)
4218 (aset table char
(format "^%c" (+ char ?
@)))
4219 (setq char
(1+ char
)))
4220 ;; printable character
4221 (while (< char ?
\177)
4222 (aset table char
(format "%c" char
))
4223 (setq char
(1+ char
)))
4225 (aset table char
"^?")
4227 (while (<= (setq char
(1+ char
)) ?
\377)
4228 (aset table char
(format "\\%o" char
)))
4230 "Vector used to map characters to a printable string.")
4232 (defun ps-control-character (char)
4233 (let* ((str (aref ps-string-control-codes char
))
4237 (char-width (ps-avg-char-width 'ps-font-for-text
))
4238 (wrappoint (ps-find-wrappoint from to char-width
)))
4239 (if (< (car wrappoint
) to
)
4241 (setq ps-width-remaining
(- ps-width-remaining
(* len char-width
)))
4242 (ps-mule-prepare-ascii-font str
)
4243 (ps-output-string str
)
4244 (ps-output " S\n")))
4246 (defun ps-color-value (x-color-value)
4247 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
4248 (/ x-color-value ps-print-color-scale
))
4251 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4253 (defun ps-color-values (x-color)
4254 (if (fboundp 'x-color-values
)
4255 (x-color-values x-color
)
4256 (error "No available function to determine X color values.")))
4261 (defun ps-color-values (x-color)
4262 (cond ((fboundp 'x-color-values
)
4263 (x-color-values x-color
))
4264 ((and (fboundp 'color-instance-rgb-components
)
4266 (color-instance-rgb-components
4267 (if (color-instance-p x-color
)
4269 (make-color-instance
4270 (if (color-specifier-p x-color
)
4271 (color-name x-color
)
4274 (error "No available function to determine X color values."))))
4278 (defun ps-face-attributes (face)
4279 "Return face attribute vector.
4281 If FACE is not in `ps-print-face-extension-alist' or in
4282 `ps-print-face-alist', insert it on `ps-print-face-alist' and
4283 return the attribute vector.
4285 If FACE is not a valid face name, it is used default face."
4286 (cdr (or (assq face ps-print-face-extension-alist
)
4287 (assq face ps-print-face-alist
)
4288 (let* ((the-face (if (facep face
) face
'default
))
4289 (new-face (ps-screen-to-bit-face the-face
)))
4290 (or (and (eq the-face
'default
)
4291 (assq the-face ps-print-face-alist
))
4292 (setq ps-print-face-alist
(cons new-face ps-print-face-alist
)))
4296 (defun ps-face-attribute-list (face-or-list)
4297 (if (listp face-or-list
)
4300 foreground background face-attr
)
4302 (setq face-attr
(ps-face-attributes (car face-or-list
))
4303 effects
(logior effects
(aref face-attr
0)))
4304 (or foreground
(setq foreground
(aref face-attr
1)))
4305 (or background
(setq background
(aref face-attr
2)))
4306 (setq face-or-list
(cdr face-or-list
)))
4307 (vector effects foreground background
))
4309 (ps-face-attributes face-or-list
)))
4312 (defconst ps-font-type
(vector nil
'bold
'italic
'bold-italic
))
4315 (defun ps-plot-with-face (from to face
)
4317 ((null face
) ; print text with null face
4318 (ps-plot-region from to
0))
4319 ((eq face
'emacs--invisible--face
)) ; skip invisible text!!!
4320 (t ; otherwise, text has a valid face
4321 (let* ((face-bit (ps-face-attribute-list face
))
4322 (effect (aref face-bit
0))
4323 (foreground (aref face-bit
1))
4324 (background (aref face-bit
2))
4325 (fg-color (if (and ps-color-p foreground
)
4326 (mapcar 'ps-color-value
4327 (ps-color-values foreground
))
4329 (bg-color (and ps-color-p background
4330 (mapcar 'ps-color-value
4331 (ps-color-values background
)))))
4334 (ps-font-number 'ps-font-for-text
4335 (or (aref ps-font-type
(logand effect
3))
4337 fg-color bg-color
(lsh effect -
2)))))
4341 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list
)
4342 (let* ((frame-font (or (face-font-instance face
)
4343 (face-font-instance 'default
)))
4344 (kind-cons (and frame-font
4346 (font-instance-properties frame-font
))))
4347 (kind-spec (cdr-safe kind-cons
))
4348 (case-fold-search t
))
4349 (or (and kind-spec
(string-match kind-regex kind-spec
))
4350 ;; Kludge-compatible:
4351 (memq face kind-list
))))
4354 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4356 (defun ps-face-bold-p (face)
4357 (or (face-bold-p face
)
4358 (memq face ps-bold-faces
)))
4360 (defun ps-face-italic-p (face)
4361 (or (face-italic-p face
)
4362 (memq face ps-italic-faces
)))
4367 (defun ps-face-bold-p (face)
4368 (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold"
4371 (defun ps-face-italic-p (face)
4372 (or (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o" ps-italic-faces
)
4373 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o" ps-italic-faces
)))
4377 (defun ps-face-underlined-p (face)
4378 (or (face-underline-p face
)
4379 (memq face ps-underlined-faces
)))
4382 ;; Ensure that face-list is fbound.
4383 (or (fboundp 'face-list
) (defalias 'face-list
'list-faces
))
4386 (defun ps-build-reference-face-lists ()
4387 ;; Ensure that face database is updated with faces on
4388 ;; `font-lock-face-attributes' (obsolete stuff)
4389 (ps-font-lock-face-attributes)
4390 ;; Now, rebuild reference face lists
4391 (setq ps-print-face-alist nil
)
4392 (if ps-auto-font-detect
4393 (mapcar 'ps-map-face
(face-list))
4394 (mapcar 'ps-set-face-bold ps-bold-faces
)
4395 (mapcar 'ps-set-face-italic ps-italic-faces
)
4396 (mapcar 'ps-set-face-underline ps-underlined-faces
))
4397 (setq ps-build-face-reference nil
))
4400 (defun ps-set-face-bold (face)
4401 (ps-set-face-attribute face
1))
4403 (defun ps-set-face-italic (face)
4404 (ps-set-face-attribute face
2))
4406 (defun ps-set-face-underline (face)
4407 (ps-set-face-attribute face
4))
4410 (defun ps-set-face-attribute (face effect
)
4411 (let ((face-bit (cdr (ps-map-face face
))))
4412 (aset face-bit
0 (logior (aref face-bit
0) effect
))))
4415 (defun ps-map-face (face)
4416 (let* ((face-map (ps-screen-to-bit-face face
))
4417 (ps-face-bit (cdr (assq (car face-map
) ps-print-face-alist
))))
4419 ;; if face exists, merge both
4420 (let ((face-bit (cdr face-map
)))
4421 (aset ps-face-bit
0 (logior (aref ps-face-bit
0) (aref face-bit
0)))
4422 (or (aref ps-face-bit
1) (aset ps-face-bit
1 (aref face-bit
1)))
4423 (or (aref ps-face-bit
2) (aset ps-face-bit
2 (aref face-bit
2))))
4424 ;; if face does not exist, insert it
4425 (setq ps-print-face-alist
(cons face-map ps-print-face-alist
)))
4429 (defun ps-screen-to-bit-face (face)
4431 (vector (logior (if (ps-face-bold-p face
) 1 0) ; bold
4432 (if (ps-face-italic-p face
) 2 0) ; italic
4433 (if (ps-face-underlined-p face
) 4 0)) ; underline
4434 (face-foreground face
)
4435 (face-background face
))))
4438 (cond ((not (eq ps-print-emacs-type
'emacs
))
4442 (defun ps-mapper (extent list
)
4443 (nconc list
(list (list (extent-start-position extent
) 'push extent
)
4444 (list (extent-end-position extent
) 'pull extent
)))
4447 (defun ps-extent-sorter (a b
)
4448 (< (extent-priority a
) (extent-priority b
)))
4452 (defun ps-print-ensure-fontified (start end
)
4453 (and (boundp 'lazy-lock-mode
) (symbol-value 'lazy-lock-mode
)
4454 (lazy-lock-fontify-region start end
)))
4456 (defun ps-generate-postscript-with-faces (from to
)
4457 ;; Some initialization...
4458 (setq ps-current-effect
0)
4460 ;; Build the reference lists of faces if necessary.
4461 (if (or ps-always-build-face-reference
4462 ps-build-face-reference
)
4464 (message "Collecting face information...")
4465 (ps-build-reference-face-lists)))
4466 ;; Set the color scale. We do it here instead of in the defvar so
4467 ;; that ps-print can be dumped into emacs. This expression can't be
4468 ;; evaluated at dump-time because X isn't initialized.
4469 (setq ps-color-p
(and ps-print-color-p
(ps-color-device))
4470 ps-print-color-scale
(if ps-color-p
4471 (float (car (ps-color-values "white")))
4473 ;; Generate some PostScript.
4475 (narrow-to-region from to
)
4476 (ps-print-ensure-fontified from to
)
4477 (let ((face 'default
)
4480 ((or (eq ps-print-emacs-type
'lucid
)
4481 (eq ps-print-emacs-type
'xemacs
))
4482 ;; Build the list of extents...
4483 (let ((a (cons 'dummy nil
))
4484 record type extent extent-list
)
4485 (map-extents 'ps-mapper nil from to a
)
4486 (setq a
(sort (cdr a
) 'car-less-than-car
)
4489 ;; Loop through the extents...
4491 (setq record
(car a
)
4493 position
(car record
)
4499 extent
(car record
))
4501 ;; Plot up to this record.
4502 ;; XEmacs 19.12: for some reason, we're getting into a
4503 ;; situation in which some of the records have
4504 ;; positions less than 'from'. Since we've narrowed
4505 ;; the buffer, this'll generate errors. This is a
4506 ;; hack, but don't call ps-plot-with-face unless from >
4508 (and (>= from
(point-min)) (<= position
(point-max))
4509 (ps-plot-with-face from position face
))
4513 (and (extent-face extent
)
4514 (setq extent-list
(sort (cons extent extent-list
)
4515 'ps-extent-sorter
))))
4518 (setq extent-list
(sort (delq extent extent-list
)
4519 'ps-extent-sorter
))))
4521 (setq face
(if extent-list
4522 (extent-face (car extent-list
))
4527 ((eq ps-print-emacs-type
'emacs
)
4528 (let ((property-change from
)
4529 (overlay-change from
)
4530 (save-buffer-invisibility-spec buffer-invisibility-spec
)
4531 (buffer-invisibility-spec nil
))
4533 (and (< property-change to
) ; Don't search for property change
4534 ; unless previous search succeeded.
4535 (setq property-change
(next-property-change from nil to
)))
4536 (and (< overlay-change to
) ; Don't search for overlay change
4537 ; unless previous search succeeded.
4538 (setq overlay-change
(min (next-overlay-change from
) to
)))
4539 (setq position
(min property-change overlay-change
))
4540 ;; The code below is not quite correct,
4541 ;; because a non-nil overlay invisible property
4542 ;; which is inactive according to the current value
4543 ;; of buffer-invisibility-spec nonetheless overrides
4544 ;; a face text property.
4546 (cond ((let ((prop (get-text-property from
'invisible
)))
4547 ;; Decide whether this invisible property
4548 ;; really makes the text invisible.
4549 (if (eq save-buffer-invisibility-spec t
)
4551 (or (memq prop save-buffer-invisibility-spec
)
4552 (assq prop save-buffer-invisibility-spec
))))
4553 'emacs--invisible--face
)
4554 ((get-text-property from
'face
))
4556 (let ((overlays (overlays-at from
))
4557 (face-priority -
1)) ; text-property
4558 (while (and overlays
4559 (not (eq face
'emacs--invisible--face
)))
4560 (let* ((overlay (car overlays
))
4561 (overlay-invisible (overlay-get overlay
'invisible
))
4562 (overlay-priority (or (overlay-get overlay
'priority
)
4564 (and (> overlay-priority face-priority
)
4566 (cond ((if (eq save-buffer-invisibility-spec t
)
4567 (not (null overlay-invisible
))
4568 (or (memq overlay-invisible
4569 save-buffer-invisibility-spec
)
4570 (assq overlay-invisible
4571 save-buffer-invisibility-spec
)))
4572 'emacs--invisible--face
)
4573 ((overlay-get overlay
'face
))
4575 face-priority overlay-priority
)))
4576 (setq overlays
(cdr overlays
))))
4577 ;; Plot up to this record.
4578 (ps-plot-with-face from position face
)
4579 (setq from position
)))))
4580 (ps-plot-with-face from to face
))))
4582 (defun ps-generate-postscript (from to
)
4583 (ps-plot-region from to
0 nil
))
4585 (defun ps-generate (buffer from to genfunc
)
4587 (let ((from (min to from
))
4589 ;; This avoids trouble if chars with read-only properties
4590 ;; are copied into ps-spool-buffer.
4591 (inhibit-read-only t
))
4593 (narrow-to-region from to
)
4594 (and ps-razzle-dazzle
4595 (message "Formatting...%3d%%" (setq ps-razchunk
0)))
4596 (setq ps-source-buffer buffer
4597 ps-spool-buffer
(get-buffer-create ps-spool-buffer-name
))
4598 (ps-init-output-queue)
4599 (let (safe-marker completed-safely needs-begin-file
)
4602 (set-buffer ps-spool-buffer
)
4603 (set-buffer-multibyte nil
)
4605 ;; Get a marker and make it point to the current end of the
4606 ;; buffer, If an error occurs, we'll delete everything from
4607 ;; the end of this marker onwards.
4608 (setq safe-marker
(make-marker))
4609 (set-marker safe-marker
(point-max))
4611 (goto-char (point-min))
4612 (or (looking-at (regexp-quote ps-adobe-tag
))
4613 (setq needs-begin-file t
))
4615 (set-buffer ps-source-buffer
)
4617 (when needs-begin-file
4619 (ps-mule-initialize))
4620 (ps-mule-begin-job from to
)
4622 (set-buffer ps-source-buffer
)
4623 (funcall genfunc from to
)
4626 (ps-end-file needs-begin-file
)
4629 ;; Setting this variable tells the unwind form that the
4630 ;; the PostScript was generated without error.
4631 (setq completed-safely t
))
4633 ;; Unwind form: If some bad mojo occurred while generating
4634 ;; PostScript, delete all the PostScript that was generated.
4635 ;; This protects the previously spooled files from getting
4637 (and (markerp safe-marker
) (not completed-safely
)
4639 (set-buffer ps-spool-buffer
)
4640 (delete-region (marker-position safe-marker
) (point-max))))))
4642 (and ps-razzle-dazzle
(message "Formatting...done"))))))
4645 (defun ps-end-job ()
4647 (let ((total-lines (cdr ps-printing-region
))
4648 (total-pages (if ps-print-only-one-header
4652 (set-buffer ps-spool-buffer
)
4653 ;; Back to the PS output buffer to set the page count
4654 (goto-char (point-min))
4655 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t
)
4656 (replace-match (format "/Lines %d def\n/PageCount %d def"
4657 total-lines total-pages
) t
))))
4660 ;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
4661 (defun ps-do-despool (filename)
4662 (if (or (not (boundp 'ps-spool-buffer
))
4663 (not (symbol-value 'ps-spool-buffer
)))
4664 (message "No spooled PostScript to print")
4667 (and ps-razzle-dazzle
(message "Saving..."))
4668 (set-buffer ps-spool-buffer
)
4669 (setq filename
(expand-file-name filename
))
4670 (let ((coding-system-for-write 'raw-text-unix
))
4671 (write-region (point-min) (point-max) filename
))
4672 (and ps-razzle-dazzle
(message "Wrote %s" filename
)))
4673 ;; Else, spool to the printer
4674 (and ps-razzle-dazzle
(message "Printing..."))
4676 (set-buffer ps-spool-buffer
)
4677 (let* ((coding-system-for-write 'raw-text-unix
)
4678 (ps-printer-name (or ps-printer-name
4679 (and (boundp 'printer-name
)
4682 (append (and (stringp ps-printer-name
)
4683 (list (concat "-P" ps-printer-name
)))
4685 (apply (or ps-print-region-function
'call-process-region
)
4686 (point-min) (point-max) ps-lpr-command nil
4687 (and (fboundp 'start-process
) 0)
4689 (ps-flatten-list ; dynamic evaluation
4690 (mapcar 'ps-eval-switch ps-lpr-switches
)))))
4691 (and ps-razzle-dazzle
(message "Printing...done")))
4692 (kill-buffer ps-spool-buffer
)))
4694 ;; Dynamic evaluation
4695 (defun ps-eval-switch (arg)
4696 (cond ((stringp arg
) arg
)
4697 ((functionp arg
) (apply arg nil
))
4698 ((symbolp arg
) (symbol-value arg
))
4699 ((consp arg
) (apply (car arg
) (cdr arg
)))
4702 ;; `ps-flatten-list' is defined here (copied from "message.el" and
4703 ;; enhanced to handle dotted pairs as well) until we can get some
4704 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
4706 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
4707 ;; => (a b c d e f g h i j)
4709 (defun ps-flatten-list (&rest list
)
4710 (ps-flatten-list-1 list
))
4712 (defun ps-flatten-list-1 (list)
4713 (cond ((null list
) nil
)
4714 ((consp list
) (append (ps-flatten-list-1 (car list
))
4715 (ps-flatten-list-1 (cdr list
))))
4718 (defun ps-kill-emacs-check ()
4720 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
4721 (buffer-modified-p ps-buffer
)
4722 (y-or-n-p "Unprinted PostScript waiting; print now? ")
4724 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
4725 (buffer-modified-p ps-buffer
)
4726 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
4727 (error "Unprinted PostScript"))))
4729 (cond ((fboundp 'add-hook
)
4730 (funcall 'add-hook
'kill-emacs-hook
'ps-kill-emacs-check
))
4732 (message "Won't override existing `kill-emacs-hook'"))
4734 (setq kill-emacs-hook
'ps-kill-emacs-check
)))
4737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4738 ;;; Sample Setup Code:
4741 ;; This stuff is for anybody that's brave enough to look this far,
4742 ;; and able to figure out how to use it. It isn't really part of
4743 ;; ps-print, but I'll leave it here in hopes it might be useful:
4745 ;; WARNING!!! The following code is *sample* code only.
4746 ;; Don't use it unless you understand what it does!
4748 (defmacro ps-prsc
()
4749 `(if (eq ps-print-emacs-type
'emacs
) [f22] 'f22))
4750 (defmacro ps-c-prsc ()
4751 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
4752 (defmacro ps-s-prsc ()
4753 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
4755 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
4756 ;; `ps-left-headers' specially for mail messages.
4757 (defun ps-rmail-mode-hook ()
4758 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
4759 (setq ps-header-lines 3
4761 ;; The left headers will display the message's subject, its
4762 ;; author, and the name of the folder it was in.
4763 '(ps-article-subject ps-article-author buffer-name)))
4765 ;; See `ps-gnus-print-article-from-summary'. This function does the
4766 ;; same thing for rmail.
4767 (defun ps-rmail-print-message-from-summary ()
4769 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
4771 ;; Used in `ps-rmail-print-article-from-summary',
4772 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
4773 (defun ps-print-message-from-summary (summary-buffer summary-default)
4774 (let ((ps-buf (or (and (boundp summary-buffer)
4775 (symbol-value summary-buffer))
4777 (and (get-buffer ps-buf)
4780 (ps-spool-buffer-with-faces)))))
4782 ;; Look in an article or mail message for the Subject: line. To be
4783 ;; placed in `ps-left-headers'.
4784 (defun ps-article-subject ()
4786 (goto-char (point-min))
4787 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
4788 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4791 ;; Look in an article or mail message for the From: line. Sorta-kinda
4792 ;; understands RFC-822 addresses and can pull the real name out where
4793 ;; it's provided. To be placed in `ps-left-headers'.
4794 (defun ps-article-author ()
4796 (goto-char (point-min))
4797 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
4798 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
4802 ;; Try first to match addresses that look like
4803 ;; thompson@wg2.waii.com (Jim Thompson)
4804 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
4805 (substring fromstring (match-beginning 1) (match-end 1)))
4807 ;; Next try to match addresses that look like
4808 ;; Jim Thompson <thompson@wg2.waii.com>
4809 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
4810 (substring fromstring (match-beginning 1) (match-end 1)))
4812 ;; Couldn't find a real name -- show the address instead.
4816 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
4817 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
4818 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
4819 ;; buffer enters that mode, so it would only work for the first time
4820 ;; we ran gnus. The second time, this hook wouldn't get set up. The
4821 ;; only alternative is `gnus-article-prepare-hook'.
4822 (defun ps-gnus-article-prepare-hook ()
4823 (setq ps-header-lines 3
4825 ;; The left headers will display the article's subject, its
4826 ;; author, and the newsgroup it was in.
4827 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
4829 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
4830 ;; `ps-left-headers' specially for mail messages.
4831 (defun ps-vm-mode-hook ()
4832 (local-set-key (ps-prsc) 'ps-vm-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 ;; Every now and then I forget to switch from the *Summary* buffer to
4840 ;; the *Article* before hitting prsc, and a nicely formatted list of
4841 ;; article subjects shows up at the printer. This function, bound to
4842 ;; prsc for the gnus *Summary* buffer means I don't have to switch
4844 ;; sb: Updated for Gnus 5.
4845 (defun ps-gnus-print-article-from-summary ()
4847 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
4849 ;; See `ps-gnus-print-article-from-summary'. This function does the
4850 ;; same thing for vm.
4851 (defun ps-vm-print-message-from-summary ()
4853 (ps-print-message-from-summary 'vm-mail-buffer ""))
4855 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
4857 (defun ps-gnus-summary-setup ()
4858 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
4860 ;; Look in an article or mail message for the Subject: line. To be
4861 ;; placed in `ps-left-headers'.
4862 (defun ps-info-file ()
4864 (goto-char (point-min))
4865 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
4866 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4869 ;; Look in an article or mail message for the Subject: line. To be
4870 ;; placed in `ps-left-headers'.
4871 (defun ps-info-node ()
4873 (goto-char (point-min))
4874 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
4875 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4878 (defun ps-info-mode-hook ()
4879 (setq ps-left-header
4880 ;; The left headers will display the node name and file name.
4881 '(ps-info-node ps-info-file)))
4883 ;; WARNING! The following function is a *sample* only, and is *not*
4884 ;; meant to be used as a whole unless you understand what the effects
4885 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
4886 ;; I'd be very surprised if it was useful to *anybody*, without
4889 (defun ps-jts-ps-setup ()
4890 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
4891 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
4892 (global-set-key (ps-c-prsc) 'ps-despool)
4893 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
4894 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
4895 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
4896 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
4897 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
4898 (setq ps-spool-duplex t
4899 ps-print-color-p nil
4900 ps-lpr-command "lpr"
4901 ps-lpr-switches '("-Jjct,duplex_long"))
4904 ;; WARNING! The following function is a *sample* only, and is *not*
4905 ;; meant to be used as a whole unless it corresponds to your needs.
4906 ;; (In fact, this is a copy of Jack's setup for ps-print --
4907 ;; I would not be that surprised if it was useful to *anybody*,
4908 ;; without modification.)
4910 (defun ps-jack-setup ()
4911 (setq ps-print-color-p nil
4912 ps-lpr-command "lpr"
4917 ps-number-of-columns 2
4919 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
4920 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
4921 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
4922 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
4923 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
4924 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
4925 ps-header-line-pad .15
4927 ps-print-header-frame t
4932 ps-font-family 'Courier
4934 ps-header-font-family 'Helvetica
4935 ps-header-font-size 6
4936 ps-header-title-font-size 8)
4940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4941 ;; To make this file smaller, some commands go in a separate file.
4942 ;; But autoload them here to make the separation invisible.
4944 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
4945 "Setup special ASCII font for STRING.
4946 STRING should contain only ASCII characters.")
4948 (autoload 'ps-mule-set-ascii-font "ps-mule"
4949 "Adjust current font if current charset is not ASCII.")
4951 (autoload 'ps-mule-plot-string "ps-mule"
4952 "Generate PostScript code for ploting characters in the region FROM and TO.
4954 It is assumed that all characters in this region belong to the same charset.
4956 Optional argument BG-COLOR specifies background color.
4960 (ENDPOS . RUN-WIDTH)
4962 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
4965 (autoload 'ps-mule-initialize "ps-mule"
4966 "Initialize global data for printing multi-byte characters.")
4968 (autoload 'ps-mule-begin-job "ps-mule"
4969 "Start printing job for multi-byte chars between FROM and TO.
4970 This checks if all multi-byte characters in the region are printable or not.")
4972 (autoload 'ps-mule-begin-page "ps-mule"
4973 "Initialize multi-byte charset for printing current page.")
4976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4980 ;;; ps-print.el ends here