1 ;;; ps-print.el --- Print text from the buffer as PostScript
3 ;; Copyright (C) 1993, 94, 95, 96, 97, 98, 1999 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: <99/12/18 13:21:51 vinicius>
15 (defconst ps-print-version
"5.0.3"
16 "ps-print.el, v 5.0.3 <99/12/18 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
401 ;; If you have a duplex-capable printer (one that prints both sides of the
402 ;; paper), set `ps-spool-duplex' to t.
403 ;; ps-print will insert blank pages to make sure each buffer starts on the
404 ;; correct side of the paper.
406 ;; The variable `ps-spool-config' specifies who is the responsable for setting
407 ;; duplex and page size switches. Valid values are:
409 ;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
410 ;; Don't forget to set `ps-lpr-switches' to select duplex
411 ;; printing for your printer.
413 ;; setpagedevice duplex and page size are configured by ps-print using the
414 ;; setpagedevice PostScript operator.
416 ;; nil duplex and page size are configured by ps-print *not* using
417 ;; the setpagedevice PostScript operator.
419 ;; Any other value is treated as nil.
421 ;; The default value is `lpr-switches'.
423 ;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
424 ;; viewing file generated using landscape. Also on some printers,
425 ;; setpagedevice affects zebra stripes; on other printers,
426 ;; setpagedevice affects the left margin.
427 ;; Besides all that, if your printer does not have the paper size
428 ;; specified by setpagedevice, your printing will be aborted.
429 ;; So, if you need to use setpagedevice, set `ps-spool-config' to
430 ;; `setpagedevice', generate a test file and send it to your printer;
431 ;; if the printed file isn't ok, set `ps-spool-config' to nil.
433 ;; The variable `ps-spool-tumble' specifies how the page images on opposite
434 ;; sides of a sheet are oriented with respect to each other. If
435 ;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
436 ;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
437 ;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
438 ;; The default value is nil.
440 ;; Some printer system prints a header page and forces the first page be printed
441 ;; on header page back, when using duplex. If your printer system has this
442 ;; behavior, set variable `ps-banner-page-when-duplexing' to t.
444 ;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
445 ;; skipped. It's like the very first character of buffer (or region) is ^L
448 ;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
455 ;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
456 ;; paper. The value specified must be between 1 and 100. The default is 1.
458 ;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
459 ;; to a high value (for example, 23). If this happens, set a lower value.
461 ;; The variable `ps-n-up-margin' specifies the margin in points between the
462 ;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
465 ;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
468 ;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
469 ;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
470 ;; filling example using a 3x4 page matrix:
472 ;; left-top 1 2 3 4 left-bottom 9 10 11 12
474 ;; 9 10 11 12 1 2 3 4
476 ;; right-top 4 3 2 1 right-bottom 12 11 10 9
478 ;; 12 11 10 9 4 3 2 1
480 ;; top-left 1 4 7 10 bottom-left 3 6 9 12
484 ;; top-right 10 7 4 1 bottom-right 12 9 6 3
488 ;; Any other value is treated as left-top.
490 ;; The default value is left-top.
493 ;; Control And 8-bit Characters
494 ;; ----------------------------
496 ;; The variable `ps-print-control-characters' specifies whether you want to see
497 ;; a printable form for control and 8-bit characters, that is, instead of
498 ;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
500 ;; Valid values for `ps-print-control-characters' are:
502 ;; 8-bit This is the value to use when you want an ASCII encoding of
503 ;; any control or non-ASCII character. Control characters are
504 ;; encoded as "^D", and non-ASCII characters have an
507 ;; control-8-bit This is the value to use when you want an ASCII encoding of
508 ;; any control character, whether it is 7 or 8-bit.
509 ;; European 8-bits accented characters are printed according
512 ;; control Only ASCII control characters have an ASCII encoding.
513 ;; European 8-bits accented characters are printed according
516 ;; nil No ASCII encoding. Any character is printed according the
519 ;; Any other value is treated as nil.
521 ;; The default is `control-8-bit'.
523 ;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
526 ;; Printing Multi-byte Buffer
527 ;; --------------------------
529 ;; See ps-mule.el for documentation.
535 ;; The variable `ps-line-number' specifies whether to number each line;
536 ;; non-nil means do so. The default is nil (don't number each line).
542 ;; Zebra stripes are a kind of background that appear "underneath" the text
543 ;; and can make the text easier to read. They look like this:
545 ;; XXXXXXXXXXXXXXXXXXXXXXXX
546 ;; XXXXXXXXXXXXXXXXXXXXXXXX
547 ;; XXXXXXXXXXXXXXXXXXXXXXXX
551 ;; XXXXXXXXXXXXXXXXXXXXXXXX
552 ;; XXXXXXXXXXXXXXXXXXXXXXXX
553 ;; XXXXXXXXXXXXXXXXXXXXXXXX
555 ;; The blocks of X's represent rectangles filled with a light gray color.
556 ;; Each rectangle extends all the way across the page.
558 ;; The height, in lines, of each rectangle is controlled by
559 ;; the variable `ps-zebra-stripe-height', which is 3 by default.
560 ;; The distance between stripes equals the height of a stripe.
562 ;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
563 ;; Non-nil means yes, nil means no. The default is nil.
565 ;; The variable `ps-zebra-gray' controls the zebra stripes gray scale.
566 ;; It should be a float number between 0.0 (black color) and 1.0 (white color).
567 ;; The default is 0.95.
569 ;; See also section How Ps-Print Has A Text And/Or Image On Background.
575 ;; ps-print has the following hook variables:
578 ;; It is evaluated once before any printing process. This is the right
579 ;; place to initialize ps-print global data.
580 ;; For an example, see section Adding a New Font Family.
582 ;; `ps-print-begin-sheet-hook'
583 ;; It is evaluated on each beginning of sheet of paper.
584 ;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
587 ;; `ps-print-begin-page-hook'
588 ;; It is evaluated on each beginning of page, except in the beginning
589 ;; of page that `ps-print-begin-sheet-hook' is evaluated.
591 ;; `ps-print-begin-column-hook'
592 ;; It is evaluated on each beginning of column, except in the beginning
593 ;; of column that `ps-print-begin-page-hook' is evaluated or that
594 ;; `ps-print-begin-sheet-hook' is evaluated.
600 ;; ps-print now knows rather precisely some fonts: the variable
601 ;; `ps-font-info-database' contains information for a list of font families
602 ;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
603 ;; `NewCenturySchlbk'). Each font family contains the font names for standard,
604 ;; bold, italic and bold-italic characters, a reference size (usually 10) and
605 ;; the corresponding line height, width of a space and average character width.
607 ;; The variable `ps-font-family' determines which font family is to be used for
608 ;; ordinary text. If its value does not correspond to a known font family, an
609 ;; error message is printed into the `*Messages*' buffer, which lists the
610 ;; currently available font families.
612 ;; The variable `ps-font-size' determines the size (in points) of the font for
613 ;; ordinary text, when generating PostScript. Its value is a float or a cons of
614 ;; floats which has the following form:
616 ;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
618 ;; Similarly, the variable `ps-header-font-family' determines which font family
619 ;; is to be used for text in the header.
621 ;; The variable `ps-header-font-size' determines the font size, in points, for
622 ;; text in the header (similar to `ps-font-size').
624 ;; The variable `ps-header-title-font-size' determines the font size, in points,
625 ;; for the top line of text in the header (similar to `ps-font-size').
628 ;; Adding a New Font Family
629 ;; ------------------------
631 ;; To use a new font family, you MUST first teach ps-print
632 ;; this font, i.e., add its information to `ps-font-info-database',
633 ;; otherwise ps-print cannot correctly place line and page breaks.
635 ;; For example, assuming `Helvetica' is unknown,
636 ;; you first need to do the following ONLY ONCE:
638 ;; - create a new buffer
639 ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
640 ;; - open this file and find the line:
641 ;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
642 ;; - delete the leading `%' (which is the PostScript comment character)
643 ;; - replace in this line `Courier' by the new font (say `Helvetica')
645 ;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
646 ;; - send this file to the printer (or to ghostscript).
647 ;; You should read the following on the output page:
649 ;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
650 ;; and a crude estimate of average character width is 5.09243
652 ;; - Add these values to the `ps-font-info-database':
653 ;; (setq ps-font-info-database
655 ;; '((Helvetica ; the family key
656 ;; (fonts (normal . "Helvetica")
657 ;; (bold . "Helvetica-Bold")
658 ;; (italic . "Helvetica-Oblique")
659 ;; (bold-italic . "Helvetica-BoldOblique"))
661 ;; (line-height . 11.56)
662 ;; (space-width . 2.78)
663 ;; (avg-char-width . 5.09243)))
664 ;; ps-font-info-database))
665 ;; - Now you can use this font family with any size:
666 ;; (setq ps-font-family 'Helvetica)
667 ;; - if you want to use this family in another emacs session, you must
668 ;; put into your `~/.emacs':
669 ;; (require 'ps-print)
670 ;; (setq ps-font-info-database (append ...)))
671 ;; if you don't want to load ps-print, you have to copy the whole value:
672 ;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
673 ;; or, use `ps-print-hook' (see section Hooks):
674 ;; (add-hook 'ps-print-hook
676 ;; (or (assq 'Helvetica ps-font-info-database)
677 ;; (setq ps-font-info-database (append ...)))))
679 ;; You can create new `mixed' font families like:
681 ;; (fonts (normal . "Courier-Bold")
682 ;; (bold . "Helvetica")
683 ;; (italic . "Zapf-Chancery-MediumItalic")
684 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
685 ;; (w3-table-hack-x-face . "LineDrawNormal"))
687 ;; (line-height . 10.55)
688 ;; (space-width . 6.0)
689 ;; (avg-char-width . 6.0))
691 ;; Now you can use your new font family with any size:
692 ;; (setq ps-font-family 'my-mixed-family)
694 ;; Note that on above example the `w3-table-hack-x-face' entry refers to
695 ;; a face symbol, so when printing this face it'll be used the font
696 ;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
697 ;; use bold and/or italic attribute, the corresponding entry (bold, italic
698 ;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
700 ;; Note also that the font family entry order is irrelevant, so the above
701 ;; example could also be written:
704 ;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
705 ;; (bold . "Helvetica")
706 ;; (bold-italic . "NewCenturySchlbk-BoldItalic")
707 ;; (italic . "Zapf-Chancery-MediumItalic")
708 ;; (normal . "Courier-Bold"))
709 ;; (avg-char-width . 6.0)
710 ;; (space-width . 6.0)
711 ;; (line-height . 10.55))
713 ;; Despite the note above, it is recommended that some convention about
714 ;; entry order be used.
716 ;; You can get information on all the fonts resident in YOUR printer
717 ;; by uncommenting the line:
718 ;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
720 ;; The PostScript file should be sent to YOUR PostScript printer.
721 ;; If you send it to ghostscript or to another PostScript printer,
722 ;; you may get slightly different results.
723 ;; Anyway, as ghostscript fonts are autoload, you won't get
727 ;; How Ps-Print Deals With Faces
728 ;; -----------------------------
730 ;; The ps-print-*-with-faces commands attempt to determine which faces
731 ;; should be printed in bold or italic, but their guesses aren't
732 ;; always right. For example, you might want to map colors into faces
733 ;; so that blue faces print in bold, and red faces in italic.
735 ;; It is possible to force ps-print to consider specific faces bold,
736 ;; italic or underline, no matter what font they are displayed in, by setting
737 ;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
738 ;; These variables contain lists of faces that ps-print should consider bold,
739 ;; italic or underline; to set them, put code like the following into your
742 ;; (setq ps-bold-faces '(my-blue-face))
743 ;; (setq ps-italic-faces '(my-red-face))
744 ;; (setq ps-underlined-faces '(my-green-face))
746 ;; Faces like bold-italic that are both bold and italic should go in
749 ;; ps-print keeps internal lists of which fonts are bold and which are
750 ;; italic; these lists are built the first time you invoke ps-print.
751 ;; For the sake of efficiency, the lists are built only once; the same
752 ;; lists are referred in later invocations of ps-print.
754 ;; Because these lists are built only once, it's possible for them to
755 ;; get out of sync, if a face changes, or if new faces are added. To
756 ;; get the lists back in sync, you can set the variable
757 ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
758 ;; next time ps-print is invoked. If you need that the lists always be
759 ;; rebuilt when ps-print is invoked, set the variable
760 ;; `ps-always-build-face-reference' to t.
763 ;; How Ps-Print Deals With Color
764 ;; -----------------------------
766 ;; ps-print detects faces with foreground and background colors
767 ;; defined and embeds color information in the PostScript image.
768 ;; The default foreground and background colors are defined by the
769 ;; variables `ps-default-fg' and `ps-default-bg'.
770 ;; On black-and-white printers, colors are displayed in grayscale.
771 ;; To turn off color output, set `ps-print-color-p' to nil.
774 ;; How Ps-Print Maps Faces
775 ;; -----------------------
777 ;; As ps-print uses PostScript to print buffers, it is possible to have
778 ;; other attributes associated with faces. So the new attributes used
781 ;; strikeout - like underline, but the line is in middle of text.
782 ;; overline - like underline, but the line is over the text.
783 ;; shadow - text will have a shadow.
784 ;; box - text will be surrounded by a box.
785 ;; outline - print characters as hollow outlines.
787 ;; See the documentation for `ps-extend-face'.
789 ;; Let's, for example, remap `font-lock-keyword-face' to another foreground
790 ;; color and bold attribute:
792 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
794 ;; If you want to use a new face, define it first with `defface',
795 ;; and then call `ps-extend-face' to specify how to print it.
798 ;; How Ps-Print Has A Text And/Or Image On Background
799 ;; --------------------------------------------------
801 ;; ps-print can print texts and/or EPS PostScript images on background; it is
802 ;; possible to define the following text attributes: font name, font size,
803 ;; initial position, angle, gray scale and pages to print.
805 ;; It has the following EPS PostScript images attributes: file name containing
806 ;; the image, initial position, X and Y scales, angle and pages to print.
808 ;; See documentation for `ps-print-background-text' and
809 ;; `ps-print-background-image'.
811 ;; For example, if we wish to print text "preliminary" on all pages and text
812 ;; "special" on page 5 and from page 11 to page 17, we could specify:
814 ;; (setq ps-print-background-text
817 ;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
818 ;; ; (upper left corner)
820 ;; "PrintHeight neg PrintPageWidth atan" ; angle
821 ;; 5 (11 . 17)) ; page list
824 ;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
825 ;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
828 ;; (setq ps-print-background-image
829 ;; '(("~/images/EPS-image1.ps"
830 ;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
831 ;; ("~/images/EPS-image2.ps"
832 ;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
833 ;; ; (upper left corner)
835 ;; 5 (11 . 17)) ; page list
838 ;; If it is not possible to read (or does not exist) an image file, that file
841 ;; The printing order is:
843 ;; 1. Print zebra stripes
844 ;; 2. Print background texts that it should be on all pages
845 ;; 3. Print background images that it should be on all pages
846 ;; 4. Print background texts only for current page (if any)
847 ;; 5. Print background images only for current page (if any)
849 ;; 7. Print buffer text (with faces, if specified) and line number
855 ;; Some tools are provided to help you customize your font setup.
857 ;; `ps-setup' returns (some part of) the current setup.
859 ;; To avoid wrapping too many lines, you may want to adjust the
860 ;; left and right margins and the font size. On UN*X systems, do:
861 ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
862 ;; to determine the longest lines of your file.
863 ;; Then, the command `ps-line-lengths' will give you the correspondence
864 ;; between a line length (number of characters) and the maximum font
865 ;; size which doesn't wrap such a line with the current ps-print setup.
867 ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
868 ;; the correspondence between a number of pages and the maximum font
869 ;; size which allow the number of lines of the current buffer or of
870 ;; its current region to fit in this number of pages.
872 ;; NOTE: line folding is not taken into account in this process and could
873 ;; change the results.
875 ;; The command `ps-print-customize' activates a customization buffer for
879 ;; New since version 1.5
880 ;; ---------------------
882 ;; Color output capability.
883 ;; Automatic detection of font attributes (bold, italic).
884 ;; Configurable headers with page numbers.
886 ;; Support for different paper sizes.
887 ;; Better conformance to PostScript Document Structure Conventions.
890 ;; New since version 2.8
891 ;; ---------------------
893 ;; [vinicius] 991211 Vinicius Jose Latorre <vinicius@cpqd.com.br>
895 ;; `ps-print-customize'.
897 ;; [vinicius] 990703 Vinicius Jose Latorre <vinicius@cpqd.com.br>
899 ;; Better customization.
900 ;; `ps-banner-page-when-duplexing' and `ps-zebra-gray'.
902 ;; [vinicius] 990513 Vinicius Jose Latorre <vinicius@cpqd.com.br>
905 ;; Hook: `ps-print-begin-sheet-hook'.
907 ;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
909 ;; `ps-print-region-function'
911 ;; [vinicius] 990301 Vinicius Jose Latorre <vinicius@cpqd.com.br>
913 ;; PostScript tumble and setpagedevice.
915 ;; [vinicius] 980922 Vinicius Jose Latorre <vinicius@cpqd.com.br>
917 ;; PostScript prologue header comment insertion.
918 ;; Skip invisible text better.
920 ;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
922 ;; Multi-byte buffer handling.
924 ;; [vinicius] 980306 Vinicius Jose Latorre <vinicius@cpqd.com.br>
926 ;; Skip invisible text.
928 ;; [vinicius] 971130 Vinicius Jose Latorre <vinicius@cpqd.com.br>
930 ;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
931 ;; `ps-print-begin-column-hook'.
932 ;; Put one header per page over the columns.
933 ;; Better database font management.
934 ;; Better control characters handling.
936 ;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
938 ;; Dynamic evaluation at print time of `ps-lpr-switches'.
939 ;; Handle control characters.
941 ;; New face attributes.
944 ;; Text and/or image on background.
946 ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
948 ;; Font family and float size for text and header.
951 ;; Tools for page setup.
954 ;; Known bugs and limitations of ps-print
955 ;; --------------------------------------
957 ;; Although color printing will work in XEmacs 19.12, it doesn't work
958 ;; well; in particular, bold or italic fonts don't print in the right
961 ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
963 ;; Automatic font-attribute detection doesn't work well, especially
964 ;; with hilit19 and older versions of get-create-face. Users having
965 ;; problems with auto-font detection should use the lists
966 ;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
967 ;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
969 ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
970 ;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
971 ;; `ps-underlined-faces' instead.
973 ;; Still too slow; could use some hand-optimization.
975 ;; Default background color isn't working.
977 ;; Faces are always treated as opaque.
979 ;; Epoch and Emacs 19 not supported. At all.
981 ;; Fixed-pitch fonts work better for line folding, but are not required.
983 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
990 ;; Avoid page break inside a paragraph.
991 ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
992 ;; Improve the memory management for big files (hard?).
993 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1000 ;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
1002 ;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1005 ;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1008 ;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1009 ;; `ps-print-control-characters' variable documentation.
1011 ;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1012 ;; database font management.
1014 ;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
1015 ;; header per page over the columns and correct line numbers when printing a
1018 ;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1019 ;; print time of `ps-lpr-switches'.
1021 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1022 ;; (his code was severely modified, but the main idea was kept).
1024 ;; Thanks to some suggestions on:
1025 ;; * Face color map: Marco Melgazzi <marco@techie.com>
1026 ;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
1027 ;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
1029 ;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1030 ;; I started from. [vinicius]
1032 ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1035 ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1036 ;; color and the invisible property.
1038 ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1039 ;; the initial port to Emacs 19. His code is no longer part of
1040 ;; ps-print, but his work is still appreciated.
1042 ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1043 ;; for adding underline support. Their code also is no longer part of
1044 ;; ps-print, but their efforts are not forgotten.
1046 ;; Thanks also to all of you who mailed code to add features to
1047 ;; ps-print; although I didn't use your code, I still appreciate your
1048 ;; sharing it with me.
1050 ;; Thanks to all who mailed comments, encouragement, and criticism.
1051 ;; Thanks also to all who responded to my survey; I had too many
1052 ;; responses to reply to them all, but I greatly appreciate your
1056 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1060 (unless (featurep 'lisp-float-type
)
1061 (error "`ps-print' requires floating point support"))
1064 ;; For Emacs 20.2 and the earlier version.
1066 (or (fboundp 'set-buffer-multibyte
)
1067 (defun set-buffer-multibyte (arg)
1068 (setq enable-multibyte-characters arg
)))
1070 (or (fboundp 'string-as-unibyte
)
1071 (defun string-as-unibyte (arg) arg
))
1073 (or (fboundp 'string-as-multibyte
)
1074 (defun string-as-multibyte (arg) arg
))
1076 (or (fboundp 'charset-after
)
1077 (defun charset-after (&optional arg
)
1078 (char-charset (char-after arg
))))
1081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1085 ;;; Interface to the command system
1087 (defgroup postscript nil
1092 (defgroup ps-print nil
1093 "PostScript generator for Emacs 19"
1098 (defgroup ps-print-horizontal nil
1099 "Horizontal page layout"
1104 (defgroup ps-print-vertical nil
1105 "Vertical page layout"
1110 (defgroup ps-print-header nil
1116 (defgroup ps-print-font nil
1117 "Fonts customization"
1122 (defgroup ps-print-color nil
1123 "Color customization"
1128 (defgroup ps-print-face nil
1129 "Faces customization"
1135 (defgroup ps-print-n-up nil
1136 "N-up customization"
1141 (defgroup ps-print-zebra nil
1142 "Zebra customization"
1147 (defgroup ps-print-background nil
1148 "Background customization"
1153 (defgroup ps-print-printer nil
1154 "Printer customization"
1159 (defgroup ps-print-page nil
1160 "Page customization"
1166 (defcustom ps-print-prologue-header nil
1167 "*PostScript prologue header comments besides that ps-print generates.
1169 `ps-print-prologue-header' may be a string or a symbol function which
1170 returns a string. Note that this string is inserted on PostScript prologue
1171 header section which is used to define some document characteristic through
1172 PostScript special comments, like \"%%Requirements: jog\\n\".
1174 ps-print always inserts the %%Requirements: comment, so if you need to insert
1175 more requirements put them first in `ps-print-prologue-header' using the
1176 \"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1177 requirements and set %%LanguageLevel: to 2, do:
1179 (setq ps-print-prologue-header
1180 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1182 The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1184 Do not forget to terminate the string with \"\\n\".
1186 For more information about PostScript document comments, see:
1187 PostScript Language Reference Manual (2nd edition)
1188 Adobe Systems Incorporated
1189 Appendix G: Document Structuring Conventions -- Version 3.0"
1190 :type
'(choice :tag
"Prologue Header"
1191 string symbol
(other :tag
"nil" nil
))
1194 (defcustom ps-printer-name
(and (boundp 'printer-name
)
1196 "*The name of a local printer for printing PostScript files.
1198 On Unix-like systems, a string value should be a name understood by
1199 lpr's -P option; a value of nil means use the value of `printer-name'
1200 instead. Any other value will be ignored.
1202 On MS-DOS and MS-Windows systems, a string value is taken as the name of
1203 the printer device or port to which PostScript files are written,
1204 provided `ps-lpr-command' is \"\". By default it is the same as
1205 `printer-name'; typical non-default settings would be \"LPT1\" to
1206 \"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1207 serial printers, or \"//hostname/printer\" for a shared network printer.
1208 You can also set it to a name of a file, in which case the output gets
1209 appended to that file. \(Note that `ps-print' package already has
1210 facilities for printing to a file, so you might as well use them instead
1211 of changing the setting of this variable.\) If you want to silently
1212 discard the printed output, set this to \"NUL\"."
1213 :type
'(choice :tag
"Printer Name"
1214 file
(other :tag
"Pipe to ps-lpr-command" pipe
))
1215 :group
'ps-print-printer
)
1217 (defcustom ps-lpr-command lpr-command
1218 "*Name of program for printing a PostScript file.
1220 On MS-DOS and MS-Windows systems, if the value is an empty string then
1221 Emacs will write directly to the printer port named by `ps-printer-name'.
1222 The programs `print' and `nprint' (the standard print programs on Windows
1223 NT and Novell Netware respectively) are handled specially, using
1224 `ps-printer-name' as the destination for output; any other program is
1225 treated like `lpr' except that an explicit filename is given as the last
1228 :group
'ps-print-printer
)
1230 (defcustom ps-lpr-switches lpr-switches
1231 "*A list of extra switches to pass to `ps-lpr-command'."
1232 :type
'(repeat string
)
1233 :group
'ps-print-printer
)
1235 (defcustom ps-print-region-function nil
1236 "*Specify a function to print the region on a PostScript printer.
1237 See definition of `call-process-region' for calling conventions. The fourth and
1238 the sixth arguments are both nil."
1240 :group
'ps-print-printer
)
1244 ;; All page dimensions are in PostScript points.
1245 ;; 1 inch == 2.54 cm == 72 points
1246 ;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1248 ;; Letter 8.5 inch x 11.0 inch
1249 ;; Legal 8.5 inch x 14.0 inch
1250 ;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1252 ;; LetterSmall 7.68 inch x 10.16 inch
1253 ;; Tabloid 11.0 inch x 17.0 inch
1254 ;; Ledger 17.0 inch x 11.0 inch
1255 ;; Statement 5.5 inch x 8.5 inch
1256 ;; Executive 7.5 inch x 10.0 inch
1257 ;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1258 ;; A4Small 7.47 inch x 10.85 inch
1259 ;; B4 10.125 inch x 14.33 inch
1260 ;; B5 7.16 inch x 10.125 inch
1262 (defcustom ps-page-dimensions-database
1263 (list (list 'a4
(/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1264 (list 'a3
(/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1265 (list 'letter
(* 72 8.5) (* 72 11.0) "Letter")
1266 (list 'legal
(* 72 8.5) (* 72 14.0) "Legal")
1267 (list 'letter-small
(* 72 7.68) (* 72 10.16) "LetterSmall")
1268 (list 'tabloid
(* 72 11.0) (* 72 17.0) "Tabloid")
1269 (list 'ledger
(* 72 17.0) (* 72 11.0) "Ledger")
1270 (list 'statement
(* 72 5.5) (* 72 8.5) "Statement")
1271 (list 'executive
(* 72 7.5) (* 72 10.0) "Executive")
1272 (list 'a4small
(* 72 7.47) (* 72 10.85) "A4Small")
1273 (list 'b4
(* 72 10.125) (* 72 14.33) "B4")
1274 (list 'b5
(* 72 7.16) (* 72 10.125) "B5"))
1275 "*List associating a symbolic paper type to its width, height and doc media.
1276 See `ps-paper-type'."
1277 :type
'(repeat (list :tag
"Paper Type"
1278 (symbol :tag
"Name")
1279 (number :tag
"Width")
1280 (number :tag
"Height")
1281 (string :tag
"Media")))
1282 :group
'ps-print-page
)
1285 (defcustom ps-paper-type
'letter
1286 "*Specify the size of paper to format for.
1287 Should be one of the paper types defined in `ps-page-dimensions-database', for
1288 example `letter', `legal' or `a4'."
1289 :type
'(symbol :validate
(lambda (wid)
1290 (if (assq (widget-value wid
)
1291 ps-page-dimensions-database
)
1293 (widget-put wid
:error
"Unknown paper size")
1295 :group
'ps-print-page
)
1297 (defcustom ps-landscape-mode nil
1298 "*Non-nil means print in landscape mode."
1300 :group
'ps-print-page
)
1302 (defcustom ps-print-control-characters
'control-8-bit
1303 "*Specify the printable form for control and 8-bit characters.
1304 That is, instead of sending, for example, a ^D (\\004) to printer,
1305 it is sent the string \"^D\".
1309 `8-bit' This is the value to use when you want an ASCII encoding of
1310 any control or non-ASCII character. Control characters are
1311 encoded as \"^D\", and non-ASCII characters have an
1314 `control-8-bit' This is the value to use when you want an ASCII encoding of
1315 any control character, whether it is 7 or 8-bit.
1316 European 8-bits accented characters are printed according
1319 `control' Only ASCII control characters have an ASCII encoding.
1320 European 8-bits accented characters are printed according
1323 nil No ASCII encoding. Any character is printed according the
1326 Any other value is treated as nil."
1327 :type
'(choice :tag
"Control Char"
1328 (const 8-bit
) (const control-8-bit
)
1329 (const control
) (other :tag
"nil" nil
))
1332 (defcustom ps-n-up-printing
1
1333 "*Specify the number of pages per sheet paper."
1335 :tag
"N Up Printing"
1338 (if (and (< 0 (widget-value wid
))
1339 (<= (widget-value wid
) 100))
1343 "Number of pages per sheet paper must be between 1 and 100.")
1345 :group
'ps-print-n-up
)
1347 (defcustom ps-n-up-margin
(/ (* 72 1.0) 2.54) ; 1 cm
1348 "*Specify the margin in points between the sheet border and n-up printing."
1350 :group
'ps-print-n-up
)
1352 (defcustom ps-n-up-border-p t
1353 "*Non-nil means a border is drawn around each page."
1355 :group
'ps-print-n-up
)
1357 (defcustom ps-n-up-filling
'left-top
1358 "*Specify how page matrix is filled on each sheet of paper.
1360 Following are the valid values for `ps-n-up-filling' with a filling example
1361 using a 3x4 page matrix:
1363 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1367 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1371 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1375 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1379 Any other value is treated as `left-top'."
1380 :type
'(choice :tag
"N-Up Filling"
1381 (const left-top
) (const left-bottom
)
1382 (const right-top
) (const right-bottom
)
1383 (const top-left
) (const bottom-left
)
1384 (const top-right
) (const bottom-right
))
1385 :group
'ps-print-n-up
)
1387 (defcustom ps-number-of-columns
(if ps-landscape-mode
2 1)
1388 "*Specify the number of columns"
1392 (defcustom ps-zebra-stripes nil
1393 "*Non-nil means print zebra stripes.
1394 See also documentation for `ps-zebra-stripe-height' and `ps-zebra-gray'."
1396 :group
'ps-print-zebra
)
1398 (defcustom ps-zebra-stripe-height
3
1399 "*Number of zebra stripe lines.
1400 See also documentation for `ps-zebra-stripes' and `ps-zebra-gray'."
1402 :group
'ps-print-zebra
)
1404 (defcustom ps-zebra-gray
0.95
1405 "*Zebra stripe gray scale.
1406 See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
1408 :group
'ps-print-zebra
)
1410 (defcustom ps-line-number nil
1411 "*Non-nil means print line number."
1415 (defcustom ps-print-background-image nil
1416 "*EPS image list to be printed on background.
1420 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1422 FILENAME is a file name which contains an EPS image or some PostScript
1423 programming like EPS.
1424 FILENAME is ignored, if it doesn't exist or is read protected.
1426 X and Y are relative positions on paper to put the image.
1427 If X and Y are nil, the image is centralized on paper.
1429 XSCALE and YSCALE are scale factor to be applied to image before printing.
1430 If XSCALE and YSCALE are nil, the original size is used.
1432 ROTATION is the image rotation angle; if nil, the default is 0.
1434 PAGES designates the page to print background image.
1435 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1437 If PAGES is nil, print background image on all pages.
1439 X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1440 an integer number or a string. If it is a string, the string should contain
1441 PostScript programming that returns a float or integer value.
1443 For example, if you wish to print an EPS image on all pages do:
1445 '((\"~/images/EPS-image.ps\"))"
1446 :type
'(repeat (list (file :tag
"EPS File")
1447 (choice :tag
"X" number string
(const nil
))
1448 (choice :tag
"Y" number string
(const nil
))
1449 (choice :tag
"X Scale" number string
(const nil
))
1450 (choice :tag
"Y Scale" number string
(const nil
))
1451 (choice :tag
"Rotation" number string
(const nil
))
1452 (repeat :tag
"Pages" :inline t
1453 (radio (integer :tag
"Page")
1455 (integer :tag
"From")
1456 (integer :tag
"To"))))))
1457 :group
'ps-print-background
)
1459 (defcustom ps-print-background-text nil
1460 "*Text list to be printed on background.
1464 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1466 STRING is the text to be printed on background.
1468 X and Y are positions on paper to put the text.
1469 If X and Y are nil, the text is positioned at lower left corner.
1471 FONT is a font name to be used on printing the text.
1472 If nil, \"Times-Roman\" is used.
1474 FONTSIZE is font size to be used, if nil, 200 is used.
1476 GRAY is the text gray factor (should be very light like 0.8).
1477 If nil, the default is 0.85.
1479 ROTATION is the text rotation angle; if nil, the angle is given by
1480 the diagonal from lower left corner to upper right corner.
1482 PAGES designates the page to print background text.
1483 PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1485 If PAGES is nil, print background text on all pages.
1487 X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1488 an integer number or a string. If it is a string, the string should contain
1489 PostScript programming that returns a float or integer value.
1491 For example, if you wish to print text \"Preliminary\" on all pages do:
1493 '((\"Preliminary\"))"
1494 :type
'(repeat (list (string :tag
"Text")
1495 (choice :tag
"X" number string
(const nil
))
1496 (choice :tag
"Y" number string
(const nil
))
1497 (choice :tag
"Font" string
(const nil
))
1498 (choice :tag
"Fontsize" number string
(const nil
))
1499 (choice :tag
"Gray" number string
(const nil
))
1500 (choice :tag
"Rotation" number string
(const nil
))
1501 (repeat :tag
"Pages" :inline t
1502 (radio (integer :tag
"Page")
1504 (integer :tag
"From")
1505 (integer :tag
"To"))))))
1506 :group
'ps-print-background
)
1508 ;;; Horizontal layout
1510 ;; ------------------------------------------
1512 ;; | lm | text | ic | text | ic | text | rm |
1514 ;; ------------------------------------------
1516 (defcustom ps-left-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1517 "*Left margin in points (1/72 inch)."
1519 :group
'ps-print-horizontal
)
1521 (defcustom ps-right-margin
(/ (* 72 2.0) 2.54) ; 2 cm
1522 "*Right margin in points (1/72 inch)."
1524 :group
'ps-print-horizontal
)
1526 (defcustom ps-inter-column
(/ (* 72 2.0) 2.54) ; 2 cm
1527 "*Horizontal space between columns in points (1/72 inch)."
1529 :group
'ps-print-horizontal
)
1545 (defcustom ps-bottom-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1546 "*Bottom margin in points (1/72 inch)."
1548 :group
'ps-print-vertical
)
1550 (defcustom ps-top-margin
(/ (* 72 1.5) 2.54) ; 1.5 cm
1551 "*Top margin in points (1/72 inch)."
1553 :group
'ps-print-vertical
)
1555 (defcustom ps-header-offset
(/ (* 72 1.0) 2.54) ; 1.0 cm
1556 "*Vertical space in points (1/72 inch) between the main text and the header."
1558 :group
'ps-print-vertical
)
1560 (defcustom ps-header-line-pad
0.15
1561 "*Portion of a header title line height to insert between the header frame
1562 and the text it contains, both in the vertical and horizontal directions."
1564 :group
'ps-print-vertical
)
1568 (defcustom ps-print-header t
1569 "*Non-nil means print a header at the top of each page.
1570 By default, the header displays the buffer name, page number, and, if
1571 the buffer is visiting a file, the file's directory. Headers are
1572 customizable by changing variables `ps-left-header' and
1575 :group
'ps-print-header
)
1577 (defcustom ps-print-only-one-header nil
1578 "*Non-nil means print only one header at the top of each page.
1579 This is useful when printing more than one column, so it is possible
1580 to have only one header over all columns or one header per column.
1581 See also `ps-print-header'."
1583 :group
'ps-print-header
)
1585 (defcustom ps-print-header-frame t
1586 "*Non-nil means draw a gaudy frame around the header."
1588 :group
'ps-print-header
)
1590 (defcustom ps-header-lines
2
1591 "*Number of lines to display in page header, when generating PostScript."
1593 :group
'ps-print-header
)
1595 (defcustom ps-show-n-of-n t
1596 "*Non-nil means show page numbers as N/M, meaning page N of M.
1597 NOTE: page numbers are displayed as part of headers,
1598 see variable `ps-print-headers'."
1600 :group
'ps-print-header
)
1602 (defcustom ps-spool-config
(if (memq system-type
1603 '(win32 w32 mswindows ms-dos windows-nt
))
1606 "*Specify who is responsable for setting duplex and page size switches.
1610 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
1611 Don't forget to set `ps-lpr-switches' to select duplex
1612 printing for your printer.
1614 `setpagedevice' duplex and page size are configured by ps-print using the
1615 setpagedevice PostScript operator.
1617 nil duplex and page size are configured by ps-print *not* using
1618 the setpagedevice PostScript operator.
1620 Any other value is treated as nil.
1622 WARNING: The setpagedevice PostScript operator affects ghostview utility when
1623 viewing file generated using landscape. Also on some printers,
1624 setpagedevice affects zebra stripes; on other printers, setpagedevice
1625 affects the left margin.
1626 Besides all that, if your printer does not have the paper size
1627 specified by setpagedevice, your printing will be aborted.
1628 So, if you need to use setpagedevice, set `ps-spool-config' to
1629 `setpagedevice', generate a test file and send it to your printer; if
1630 the printed file isn't ok, set `ps-spool-config' to nil."
1631 :type
'(choice :tag
"Spool Config"
1632 (const lpr-switches
) (const setpagedevice
)
1633 (other :tag
"nil" nil
))
1634 :group
'ps-print-header
)
1636 (defcustom ps-spool-duplex nil
; Not many people have duplex printers,
1637 ; so default to nil.
1638 "*Non-nil generates PostScript for a two-sided printer.
1639 For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
1640 blank pages as needed between print jobs so that the next buffer printed will
1641 start on the right page. Also, if headers are turned on, the headers will be
1642 reversed on duplex printers so that the page numbers fall to the left on
1643 even-numbered pages.
1645 See also `ps-spool-tumble'."
1647 :group
'ps-print-header
)
1649 (defcustom ps-spool-tumble nil
1650 "*Specify how the page images on opposite sides of a sheet are oriented.
1651 If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
1652 right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
1655 It has effect only when `ps-spool-duplex' is non-nil."
1657 :group
'ps-print-header
)
1661 (defcustom ps-font-info-database
1662 '((Courier ; the family key
1663 (fonts (normal .
"Courier")
1664 (bold .
"Courier-Bold")
1665 (italic .
"Courier-Oblique")
1666 (bold-italic .
"Courier-BoldOblique"))
1668 (line-height .
10.55)
1670 (avg-char-width .
6.0))
1671 (Helvetica ; the family key
1672 (fonts (normal .
"Helvetica")
1673 (bold .
"Helvetica-Bold")
1674 (italic .
"Helvetica-Oblique")
1675 (bold-italic .
"Helvetica-BoldOblique"))
1677 (line-height .
11.56)
1678 (space-width .
2.78)
1679 (avg-char-width .
5.09243))
1681 (fonts (normal .
"Times-Roman")
1682 (bold .
"Times-Bold")
1683 (italic .
"Times-Italic")
1684 (bold-italic .
"Times-BoldItalic"))
1686 (line-height .
11.0)
1688 (avg-char-width .
4.71432))
1690 (fonts (normal .
"Palatino-Roman")
1691 (bold .
"Palatino-Bold")
1692 (italic .
"Palatino-Italic")
1693 (bold-italic .
"Palatino-BoldItalic"))
1695 (line-height .
12.1)
1697 (avg-char-width .
5.08676))
1699 (fonts (normal .
"Helvetica-Narrow")
1700 (bold .
"Helvetica-Narrow-Bold")
1701 (italic .
"Helvetica-Narrow-Oblique")
1702 (bold-italic .
"Helvetica-Narrow-BoldOblique"))
1704 (line-height .
11.56)
1705 (space-width .
2.2796)
1706 (avg-char-width .
4.17579))
1708 (fonts (normal .
"NewCenturySchlbk-Roman")
1709 (bold .
"NewCenturySchlbk-Bold")
1710 (italic .
"NewCenturySchlbk-Italic")
1711 (bold-italic .
"NewCenturySchlbk-BoldItalic"))
1713 (line-height .
12.15)
1714 (space-width .
2.78)
1715 (avg-char-width .
5.31162))
1716 ;; got no bold for the next ones
1718 (fonts (normal .
"AvantGarde-Book")
1719 (italic .
"AvantGarde-BookOblique"))
1721 (line-height .
11.77)
1722 (space-width .
2.77)
1723 (avg-char-width .
5.45189))
1725 (fonts (normal .
"AvantGarde-Demi")
1726 (italic .
"AvantGarde-DemiOblique"))
1728 (line-height .
12.72)
1730 (avg-char-width .
5.51351))
1732 (fonts (normal .
"Bookman-Demi")
1733 (italic .
"Bookman-DemiItalic"))
1735 (line-height .
11.77)
1737 (avg-char-width .
6.05946))
1739 (fonts (normal .
"Bookman-Light")
1740 (italic .
"Bookman-LightItalic"))
1742 (line-height .
11.79)
1744 (avg-char-width .
5.67027))
1745 ;; got no bold and no italic for the next ones
1747 (fonts (normal .
"Symbol"))
1749 (line-height .
13.03)
1751 (avg-char-width .
3.24324))
1753 (fonts (normal .
"Zapf-Dingbats"))
1755 (line-height .
9.63)
1756 (space-width .
2.78)
1757 (avg-char-width .
2.78))
1758 (Zapf-Chancery-MediumItalic
1759 (fonts (normal .
"Zapf-Chancery-MediumItalic"))
1761 (line-height .
11.45)
1763 (avg-char-width .
4.10811))
1765 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1766 reference size, line height, space width, average character width.
1767 To get the info for another specific font (say Helvetica), do the following:
1768 - create a new buffer
1769 - generate the PostScript image to a file (C-u M-x ps-print-buffer)
1770 - open this file and delete the leading `%' (which is the PostScript
1771 comment character) from the line
1772 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
1774 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
1775 - add the values to `ps-font-info-database'.
1776 You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
1777 :type
'(repeat (list :tag
"Font Definition"
1778 (symbol :tag
"Font Family")
1780 (const :format
"" fonts
)
1781 (repeat :tag
"Faces"
1782 (cons (choice (const normal
)
1786 (symbol :tag
"Face"))
1787 (string :tag
"Font Name"))))
1789 (const :format
"" size
)
1790 (number :tag
"Reference Size"))
1792 (const :format
"" line-height
)
1793 (number :tag
"Line Height"))
1795 (const :format
"" space-width
)
1796 (number :tag
"Space Width"))
1798 (const :format
"" avg-char-width
)
1799 (number :tag
"Average Character Width"))))
1800 :group
'ps-print-font
)
1802 (defcustom ps-font-family
'Courier
1803 "*Font family name for ordinary text, when generating PostScript."
1805 :group
'ps-print-font
)
1807 (defcustom ps-font-size
'(7 .
8.5)
1808 "*Font size, in points, for ordinary text, when generating PostScript."
1809 :type
'(choice (number :tag
"Text Size")
1810 (cons :tag
"Landscape/Portrait"
1811 (number :tag
"Landscape Text Size")
1812 (number :tag
"Portrait Text Size")))
1813 :group
'ps-print-font
)
1815 (defcustom ps-header-font-family
'Helvetica
1816 "*Font family name for text in the header, when generating PostScript."
1818 :group
'ps-print-font
)
1820 (defcustom ps-header-font-size
'(10 .
12)
1821 "*Font size, in points, for text in the header, when generating PostScript."
1822 :type
'(choice (number :tag
"Header Size")
1823 (cons :tag
"Landscape/Portrait"
1824 (number :tag
"Landscape Header Size")
1825 (number :tag
"Portrait Header Size")))
1826 :group
'ps-print-font
)
1828 (defcustom ps-header-title-font-size
'(12 .
14)
1829 "*Font size, in points, for the top line of text in header, in PostScript."
1830 :type
'(choice (number :tag
"Header Title Size")
1831 (cons :tag
"Landscape/Portrait"
1832 (number :tag
"Landscape Header Title Size")
1833 (number :tag
"Portrait Header Title Size")))
1834 :group
'ps-print-font
)
1838 ;; Printing color requires x-color-values.
1839 (defcustom ps-print-color-p
(or (fboundp 'x-color-values
) ; Emacs
1840 (fboundp 'color-instance-rgb-components
))
1842 "*Non-nil means print the buffer's text in color."
1844 :group
'ps-print-color
)
1846 (defcustom ps-default-fg
'(0.0
0.0 0.0)
1847 "*RGB values of the default foreground color. Defaults to black."
1848 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1849 :group
'ps-print-color
)
1851 (defcustom ps-default-bg
'(1.0
1.0 1.0)
1852 "*RGB values of the default background color. Defaults to white."
1853 :type
'(list (number :tag
"Red") (number :tag
"Green") (number :tag
"Blue"))
1854 :group
'ps-print-color
)
1856 (defcustom ps-auto-font-detect t
1857 "*Non-nil means automatically detect bold/italic face attributes.
1858 If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
1859 and `ps-underlined-faces'."
1861 :group
'ps-print-font
)
1863 (defcustom ps-bold-faces
1864 (unless ps-print-color-p
1865 '(font-lock-function-name-face
1866 font-lock-builtin-face
1867 font-lock-variable-name-face
1868 font-lock-keyword-face
1869 font-lock-warning-face
))
1870 "*A list of the \(non-bold\) faces that should be printed in bold font.
1871 This applies to generating PostScript."
1872 :type
'(repeat face
)
1873 :group
'ps-print-face
)
1875 (defcustom ps-italic-faces
1876 (unless ps-print-color-p
1877 '(font-lock-variable-name-face
1879 font-lock-string-face
1880 font-lock-comment-face
1881 font-lock-warning-face
))
1882 "*A list of the \(non-italic\) faces that should be printed in italic font.
1883 This applies to generating PostScript."
1884 :type
'(repeat face
)
1885 :group
'ps-print-face
)
1887 (defcustom ps-underlined-faces
1888 (unless ps-print-color-p
1889 '(font-lock-function-name-face
1890 font-lock-constant-face
1891 font-lock-warning-face
))
1892 "*A list of the \(non-underlined\) faces that should be printed underlined.
1893 This applies to generating PostScript."
1894 :type
'(repeat face
)
1895 :group
'ps-print-face
)
1897 (defcustom ps-left-header
1898 (list 'ps-get-buffer-name
'ps-header-dirpart
)
1899 "*The items to display (each on a line) on the left part of the page header.
1900 This applies to generating PostScript.
1902 The value should be a list of strings and symbols, each representing an
1903 entry in the PostScript array HeaderLinesLeft.
1905 Strings are inserted unchanged into the array; those representing
1906 PostScript string literals should be delimited with PostScript string
1907 delimiters '(' and ')'.
1909 For symbols with bound functions, the function is called and should
1910 return a string to be inserted into the array. For symbols with bound
1911 values, the value should be a string to be inserted into the array.
1912 In either case, function or variable, the string value has PostScript
1913 string delimiters added to it."
1914 :type
'(repeat (choice string symbol
))
1915 :group
'ps-print-header
)
1917 (defcustom ps-right-header
1918 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy
'time-stamp-hh
:mm
:ss
)
1919 "*The items to display (each on a line) on the right part of the page header.
1920 This applies to generating PostScript.
1922 See the variable `ps-left-header' for a description of the format of
1924 :type
'(repeat (choice string symbol
))
1925 :group
'ps-print-header
)
1927 (defcustom ps-razzle-dazzle t
1928 "*Non-nil means report progress while formatting buffer."
1932 (defcustom ps-adobe-tag
"%!PS-Adobe-3.0\n"
1933 "*Contains the header line identifying the output as PostScript.
1934 By default, `ps-adobe-tag' contains the standard identifier. Some
1935 printers require slightly different versions of this line."
1939 (defcustom ps-build-face-reference t
1940 "*Non-nil means build the reference face lists.
1942 ps-print sets this value to nil after it builds its internal reference
1943 lists of bold and italic faces. By settings its value back to t, you
1944 can force ps-print to rebuild the lists the next time you invoke one
1945 of the ...-with-faces commands.
1947 You should set this value back to t after you change the attributes of
1948 any face, or create new faces. Most users shouldn't have to worry
1949 about its setting, though."
1951 :group
'ps-print-face
)
1953 (defcustom ps-always-build-face-reference nil
1954 "*Non-nil means always rebuild the reference face lists.
1956 If this variable is non-nil, ps-print will rebuild its internal
1957 reference lists of bold and italic faces *every* time one of the
1958 ...-with-faces commands is called. Most users shouldn't need to set this
1961 :group
'ps-print-face
)
1963 (defcustom ps-banner-page-when-duplexing nil
1964 "*Non-nil means the very first page is skipped.
1965 It's like the very first character of buffer (or region) is ^L (\\014)."
1967 :group
'ps-print-header
)
1969 (defcustom ps-postscript-code-directory data-directory
1970 "*Directory where it's located the PostScript prologue file used by ps-print.
1971 By default, this directory is the same as in the variable `data-directory'."
1976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1981 (defun ps-print-customize ()
1982 "Customization of ps-print group."
1984 (customize-group 'ps-print
))
1987 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1992 (defun ps-print-buffer (&optional filename
)
1993 "Generate and print a PostScript image of the buffer.
1995 Interactively, when you use a prefix argument (C-u), the command
1996 prompts the user for a file name, and saves the PostScript image
1997 in that file instead of sending it to the printer.
1999 Noninteractively, the argument FILENAME is treated as follows: if it
2000 is nil, send the image to the printer. If FILENAME is a string, save
2001 the PostScript image in a file with that name."
2002 (interactive (list (ps-print-preprint current-prefix-arg
)))
2003 (ps-print-without-faces (point-min) (point-max) filename
))
2007 (defun ps-print-buffer-with-faces (&optional filename
)
2008 "Generate and print a PostScript image of the buffer.
2009 Like `ps-print-buffer', but includes font, color, and underline
2010 information in the generated image. This command works only if you
2011 are using a window system, so it has a way to determine color values."
2012 (interactive (list (ps-print-preprint current-prefix-arg
)))
2013 (ps-print-with-faces (point-min) (point-max) filename
))
2017 (defun ps-print-region (from to
&optional filename
)
2018 "Generate and print a PostScript image of the region.
2019 Like `ps-print-buffer', but prints just the current region."
2020 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2021 (ps-print-without-faces from to filename t
))
2025 (defun ps-print-region-with-faces (from to
&optional filename
)
2026 "Generate and print a PostScript image of the region.
2027 Like `ps-print-region', but includes font, color, and underline
2028 information in the generated image. This command works only if you
2029 are using a window system, so it has a way to determine color values."
2030 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg
)))
2031 (ps-print-with-faces from to filename t
))
2035 (defun ps-spool-buffer ()
2036 "Generate and spool a PostScript image of the buffer.
2037 Like `ps-print-buffer' except that the PostScript image is saved in a
2038 local buffer to be sent to the printer later.
2040 Use the command `ps-despool' to send the spooled images to the printer."
2042 (ps-spool-without-faces (point-min) (point-max)))
2046 (defun ps-spool-buffer-with-faces ()
2047 "Generate and spool a PostScript image of the buffer.
2048 Like `ps-spool-buffer', but includes font, color, and underline
2049 information in the generated image. This command works only if you
2050 are using a window system, so it has a way to determine color values.
2052 Use the command `ps-despool' to send the spooled images to the printer."
2054 (ps-spool-with-faces (point-min) (point-max)))
2058 (defun ps-spool-region (from to
)
2059 "Generate a PostScript image of the region and spool locally.
2060 Like `ps-spool-buffer', but spools just the current region.
2062 Use the command `ps-despool' to send the spooled images to the printer."
2064 (ps-spool-without-faces from to t
))
2068 (defun ps-spool-region-with-faces (from to
)
2069 "Generate a PostScript image of the region and spool locally.
2070 Like `ps-spool-region', but includes font, color, and underline
2071 information in the generated image. This command works only if you
2072 are using a window system, so it has a way to determine color values.
2074 Use the command `ps-despool' to send the spooled images to the printer."
2076 (ps-spool-with-faces from to t
))
2079 (defun ps-despool (&optional filename
)
2080 "Send the spooled PostScript to the printer.
2082 Interactively, when you use a prefix argument (C-u), the command
2083 prompts the user for a file name, and saves the spooled PostScript
2084 image in that file instead of sending it to the printer.
2086 Noninteractively, the argument FILENAME is treated as follows: if it
2087 is nil, send the image to the printer. If FILENAME is a string, save
2088 the PostScript image in a file with that name."
2089 (interactive (list (ps-print-preprint current-prefix-arg
)))
2090 (ps-do-despool filename
))
2093 (defun ps-line-lengths ()
2094 "Display the correspondence between a line length and a font size,
2095 using the current ps-print setup.
2096 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2098 (ps-line-lengths-internal))
2101 (defun ps-nb-pages-buffer (nb-lines)
2102 "Display number of pages to print this buffer, for various font heights.
2103 The table depends on the current ps-print setup."
2104 (interactive (list (count-lines (point-min) (point-max))))
2105 (ps-nb-pages nb-lines
))
2108 (defun ps-nb-pages-region (nb-lines)
2109 "Display number of pages to print the region, for various font heights.
2110 The table depends on the current ps-print setup."
2111 (interactive (list (count-lines (mark) (point))))
2112 (ps-nb-pages nb-lines
))
2116 "Return the current PostScript-generation setup."
2119 \(setq ps-print-color-p %s
2123 ps-print-region-function %s
2126 ps-landscape-mode %s
2127 ps-number-of-columns %s
2130 ps-zebra-stripe-height %s
2134 ps-print-control-characters %s
2136 ps-print-background-image %s
2138 ps-print-background-text %s
2140 ps-print-prologue-header %s
2148 ps-header-line-pad %s
2150 ps-print-only-one-header %s
2151 ps-print-header-frame %s
2157 ps-banner-page-when-duplexing %s
2164 ps-multibyte-buffer %s
2167 ps-header-font-family %s
2168 ps-header-font-size %s
2169 ps-header-title-font-size %s)
2173 (ps-print-quote ps-lpr-switches
)
2175 (ps-print-quote ps-print-region-function
)
2176 (ps-print-quote ps-paper-type
)
2178 ps-number-of-columns
2180 ps-zebra-stripe-height
2183 (ps-print-quote ps-print-control-characters
)
2184 (ps-print-quote ps-print-background-image
)
2185 (ps-print-quote ps-print-background-text
)
2186 (ps-print-quote ps-print-prologue-header
)
2195 ps-print-only-one-header
2196 ps-print-header-frame
2199 (ps-print-quote ps-spool-config
)
2202 ps-banner-page-when-duplexing
2206 (ps-print-quote ps-n-up-filling
)
2207 (ps-print-quote ps-multibyte-buffer
) ; see `ps-mule.el'
2208 (ps-print-quote ps-font-family
)
2209 (ps-print-quote ps-font-size
)
2210 (ps-print-quote ps-header-font-family
)
2211 (ps-print-quote ps-header-font-size
)
2212 (ps-print-quote ps-header-title-font-size
)))
2215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2216 ;; Utility functions and variables:
2219 (defun ps-print-quote (sym)
2222 ((or (symbolp sym
) (listp sym
))
2229 (defvar ps-print-emacs-type
2230 (cond ((string-match "XEmacs" emacs-version
) 'xemacs
)
2231 ((string-match "Lucid" emacs-version
) 'lucid
)
2232 ((string-match "Epoch" emacs-version
) 'epoch
)
2235 (if (or (eq ps-print-emacs-type
'lucid
)
2236 (eq ps-print-emacs-type
'xemacs
))
2237 (if (< emacs-minor-version
12)
2238 (setq ps-print-color-p nil
))
2239 (require 'faces
)) ; face-font, face-underline-p,
2242 ;; Return t if the device (which can be changed during an emacs session)
2243 ;; can handle colors.
2244 ;; This is function is not yet implemented for GNU emacs.
2245 (cond ((and (eq ps-print-emacs-type
'xemacs
)
2246 (>= emacs-minor-version
12)) ; xemacs
2247 (defun ps-color-device ()
2248 (eq (device-class) 'color
))
2252 (defun ps-color-device ()
2257 (require 'time-stamp
)
2260 (defun ps-prologue-file (filenumber)
2263 (or (find-file-noselect
2264 (format "%sps-prin%d.ps"
2265 ps-postscript-code-directory filenumber
)
2267 (error "ps-print PostScript prologue %d file was not found."
2272 (kill-buffer buffer
)))))
2275 (defvar ps-mark-code-directory nil
)
2277 (defvar ps-print-prologue-1
""
2278 "ps-print PostScript prologue begin.")
2280 (defvar ps-print-prologue-2
""
2281 "ps-print PostScript prologue end.")
2283 (defvar ps-print-duplex-feature
""
2284 "ps-print PostScript duplex feature.")
2286 ;; Start Editing Here:
2288 (defvar ps-source-buffer nil
)
2289 (defvar ps-spool-buffer-name
"*PostScript*")
2290 (defvar ps-spool-buffer nil
)
2292 (defvar ps-output-head nil
)
2293 (defvar ps-output-tail nil
)
2295 (defvar ps-page-postscript
0)
2296 (defvar ps-page-order
0)
2297 (defvar ps-page-count
0)
2298 (defvar ps-showline-count
1)
2300 (defvar ps-control-or-escape-regexp nil
)
2302 (defvar ps-background-pages nil
)
2303 (defvar ps-background-all-pages nil
)
2304 (defvar ps-background-text-count
0)
2305 (defvar ps-background-image-count
0)
2307 (defvar ps-current-font
0)
2308 (defvar ps-default-color
(and ps-print-color-p ps-default-fg
)) ; black
2309 (defvar ps-current-color ps-default-color
)
2310 (defvar ps-current-bg nil
)
2312 (defvar ps-razchunk
0)
2314 (defvar ps-color-p nil
)
2315 (defvar ps-color-format
2316 (if (eq ps-print-emacs-type
'emacs
)
2318 ;; Emacs understands the %f format; we'll use it to limit color RGB
2319 ;; values to three decimals to cut down some on the size of the
2320 ;; PostScript output.
2323 ;; Lucid emacsen will have to make do with %s (princ) for floats.
2326 ;; These values determine how much print-height to deduct when headers
2327 ;; are turned on. This is a pretty clumsy way of handling it, but
2328 ;; it'll do for now.
2330 (defvar ps-header-pad
0
2331 "Vertical and horizontal space between the header frame and the text.
2332 This is in units of points (1/72 inch).")
2334 ;; Define accessors to the dimensions list.
2336 (defmacro ps-page-dimensions-get-width
(dims) `(nth 0 ,dims
))
2337 (defmacro ps-page-dimensions-get-height
(dims) `(nth 1 ,dims
))
2338 (defmacro ps-page-dimensions-get-media
(dims) `(nth 2 ,dims
))
2340 (defvar ps-landscape-page-height nil
)
2342 (defvar ps-print-width nil
)
2343 (defvar ps-print-height nil
)
2345 (defvar ps-height-remaining nil
)
2346 (defvar ps-width-remaining nil
)
2348 (defvar ps-print-color-scale nil
)
2350 (defvar ps-font-size-internal nil
)
2351 (defvar ps-header-font-size-internal nil
)
2352 (defvar ps-header-title-font-size-internal nil
)
2355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2356 ;; Internal Variables
2359 (defvar ps-print-face-extension-alist nil
2360 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
2361 An element of this list has the following form:
2363 (FACE . [BITS FG BG])
2365 FACE is a symbol denoting a face name
2366 BITS is a bit vector, where each bit correspond
2367 to a feature (bold, underline, etc)
2368 (see documentation for `ps-print-face-map-alist')
2369 FG foreground color (string or nil)
2370 BG background color (string or nil)
2372 Don't change this list directly; instead,
2373 use `ps-extend-face' and `ps-extend-face-list'.
2374 See documentation for `ps-extend-face' for valid extension symbol.")
2377 (defvar ps-print-face-alist nil
2378 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2380 An element of this list has the same form as an element of
2381 `ps-print-face-extension-alist'.
2383 Don't change this list directly; this list is used by `ps-face-attributes',
2384 `ps-map-face' and `ps-build-reference-face-lists'.")
2387 (defconst ps-print-face-map-alist
2396 "Alist of all features and the corresponding bit mask.
2397 Each symbol correspond to one bit in a bit vector.")
2400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2405 (defun ps-extend-face-list (face-extension-list &optional merge-p
)
2406 "Extend face in `ps-print-face-extension-alist'.
2408 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2409 with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2411 The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2413 See `ps-extend-face' for documentation."
2414 (while face-extension-list
2415 (ps-extend-face (car face-extension-list
) merge-p
)
2416 (setq face-extension-list
(cdr face-extension-list
))))
2420 (defun ps-extend-face (face-extension &optional merge-p
)
2421 "Extend face in `ps-print-face-extension-alist'.
2423 If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2424 with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2426 The elements of FACE-EXTENSION list have the form:
2428 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2430 FACE-NAME is a face name symbol.
2432 FOREGROUND and BACKGROUND may be nil or a string that denotes the
2433 foreground and background colors respectively.
2435 EXTENSION is one of the following symbols:
2436 bold - use bold font.
2437 italic - use italic font.
2438 underline - put a line under text.
2439 strikeout - like underline, but the line is in middle of text.
2440 overline - like underline, but the line is over the text.
2441 shadow - text will have a shadow.
2442 box - text will be surrounded by a box.
2443 outline - print characters as hollow outlines.
2445 If EXTENSION is any other symbol, it is ignored."
2446 (let* ((face-name (nth 0 face-extension
))
2447 (foreground (nth 1 face-extension
))
2448 (background (nth 2 face-extension
))
2449 (ps-face (cdr (assq face-name ps-print-face-extension-alist
)))
2450 (face-vector (or ps-face
(vector 0 nil nil
)))
2451 (face-bit (ps-extension-bit face-extension
)))
2453 (aset face-vector
0 (if merge-p
2454 (logior (aref face-vector
0) face-bit
)
2456 (and foreground
(stringp foreground
) (aset face-vector
1 foreground
))
2457 (and background
(stringp background
) (aset face-vector
2 background
))
2458 ;; if face does not exist, insert it
2460 (setq ps-print-face-extension-alist
2461 (cons (cons face-name face-vector
)
2462 ps-print-face-extension-alist
)))))
2465 (defun ps-extension-bit (face-extension)
2467 ;; map valid symbol extension to bit vector
2468 (setq face-extension
(cdr (cdr face-extension
)))
2469 (while (setq face-extension
(cdr face-extension
))
2470 (setq face-bit
(logior face-bit
2471 (or (cdr (assq (car face-extension
)
2472 ps-print-face-map-alist
))
2477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2478 ;; Adapted from font-lock: (obsolete stuff)
2479 ;; Originally face attributes were specified via `font-lock-face-attributes'.
2480 ;; Users then changed the default face attributes by setting that variable.
2481 ;; However, we try and be back-compatible and respect its value if set except
2482 ;; for faces where M-x customize has been used to save changes for the face.
2485 (defun ps-font-lock-face-attributes ()
2486 (and (boundp 'font-lock-mode
) (symbol-value 'font-lock-mode
)
2487 (boundp 'font-lock-face-attributes
)
2488 (let ((face-attributes font-lock-face-attributes
))
2489 (while face-attributes
2490 (let* ((face-attribute
2491 (car (prog1 face-attributes
2492 (setq face-attributes
(cdr face-attributes
)))))
2493 (face (car face-attribute
)))
2494 ;; Rustle up a `defface' SPEC from a
2495 ;; `font-lock-face-attributes' entry.
2496 (unless (get face
'saved-face
)
2497 (let ((foreground (nth 1 face-attribute
))
2498 (background (nth 2 face-attribute
))
2499 (bold-p (nth 3 face-attribute
))
2500 (italic-p (nth 4 face-attribute
))
2501 (underline-p (nth 5 face-attribute
))
2504 (setq face-spec
(cons ':foreground
2505 (cons foreground face-spec
))))
2507 (setq face-spec
(cons ':background
2508 (cons background face-spec
))))
2510 (setq face-spec
(append '(:bold t
) face-spec
)))
2512 (setq face-spec
(append '(:italic t
) face-spec
)))
2514 (setq face-spec
(append '(:underline t
) face-spec
)))
2515 (custom-declare-face face
(list (list t face-spec
)) nil
)
2519 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2520 ;; Internal functions and variables
2523 (make-local-hook 'ps-print-hook
)
2524 (make-local-hook 'ps-print-begin-sheet-hook
)
2525 (make-local-hook 'ps-print-begin-page-hook
)
2526 (make-local-hook 'ps-print-begin-column-hook
)
2529 (defun ps-print-without-faces (from to
&optional filename region-p
)
2530 (ps-spool-without-faces from to region-p
)
2531 (ps-do-despool filename
))
2534 (defun ps-spool-without-faces (from to
&optional region-p
)
2535 (run-hooks 'ps-print-hook
)
2536 (ps-printing-region region-p
)
2537 (ps-generate (current-buffer) from to
'ps-generate-postscript
))
2540 (defun ps-print-with-faces (from to
&optional filename region-p
)
2541 (ps-spool-with-faces from to region-p
)
2542 (ps-do-despool filename
))
2545 (defun ps-spool-with-faces (from to
&optional region-p
)
2546 (run-hooks 'ps-print-hook
)
2547 (ps-printing-region region-p
)
2548 (ps-generate (current-buffer) from to
'ps-generate-postscript-with-faces
))
2551 (defun ps-count-lines (from to
)
2552 (+ (count-lines from to
)
2555 (if (= (current-column) 0) 1 0))))
2558 (defvar ps-printing-region nil
2559 "Variable used to indicate if the region that ps-print is printing.
2560 It is a cons, the car of which is the line number where the region begins, and
2561 its cdr is the total number of lines in the buffer. Formatting functions can
2562 use this information to print the original line number (and not the number of
2563 lines printed), and to indicate in the header that the printout is of a partial
2567 (defvar ps-printing-region-p nil
2568 "Non-nil means ps-print is printing a region.")
2571 (defun ps-printing-region (region-p)
2572 (setq ps-printing-region-p region-p
2575 (ps-count-lines (point-min) (region-beginning))
2577 (ps-count-lines (point-min) (point-max)))))
2580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2581 ;; Internal functions
2584 (defsubst ps-font-alist
(font-sym)
2585 (get font-sym
'fonts
))
2587 (defun ps-font (font-sym font-type
)
2588 "Font family name for text of `font-type', when generating PostScript."
2589 (let* ((font-list (ps-font-alist font-sym
))
2590 (normal-font (cdr (assq 'normal font-list
))))
2591 (while (and font-list
(not (eq font-type
(car (car font-list
)))))
2592 (setq font-list
(cdr font-list
)))
2593 (or (cdr (car font-list
)) normal-font
)))
2595 (defun ps-fonts (font-sym)
2596 (mapcar 'cdr
(ps-font-alist font-sym
)))
2598 (defun ps-font-number (font-sym font-type
)
2599 (or (ps-alist-position font-type
(ps-font-alist font-sym
))
2602 (defsubst ps-line-height
(font-sym)
2603 "The height of a line, for generating PostScript.
2604 This is the value that ps-print uses to determine the height,
2605 y-dimension, of the lines of text it has printed, and thus affects the
2606 point at which page-breaks are placed.
2607 The line-height is *not* the same as the point size of the font."
2608 (get font-sym
'line-height
))
2610 (defsubst ps-title-line-height
(font-sym)
2611 "The height of a `title' line, for generating PostScript.
2612 This is the value that ps-print uses to determine the height,
2613 y-dimension, of the lines of text it has printed, and thus affects the
2614 point at which page-breaks are placed.
2615 The title-line-height is *not* the same as the point size of the font."
2616 (get font-sym
'title-line-height
))
2618 (defsubst ps-space-width
(font-sym)
2619 "The width of a space character, for generating PostScript.
2620 This value is used in expanding tab characters."
2621 (get font-sym
'space-width
))
2623 (defsubst ps-avg-char-width
(font-sym)
2624 "The average width, in points, of a character, for generating PostScript.
2625 This is the value that ps-print uses to determine the length,
2626 x-dimension, of the text it has printed, and thus affects the point at
2627 which long lines wrap around."
2628 (get font-sym
'avg-char-width
))
2630 (defun ps-line-lengths-internal ()
2631 "Display the correspondence between a line length and a font size,
2632 using the current ps-print setup.
2633 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2634 (let ((buf (get-buffer-create "*Line-lengths*"))
2635 (ifs ps-font-size-internal
) ; initial font size
2636 (icw (ps-avg-char-width 'ps-font-for-text
)) ; initial character width
2637 (print-width (progn (ps-get-page-dimensions)
2639 (ps-setup (ps-setup)) ; setup for the current buffer
2640 (fs-min 5) ; minimum font size
2641 cw-min
; minimum character width
2642 nb-cpl-max
; maximum nb of characters per line
2643 (fs-max 14) ; maximum font size
2644 cw-max
; maximum character width
2645 nb-cpl-min
; minimum nb of characters per line
2646 fs
; current font size
2647 cw
; current character width
2648 nb-cpl
; current nb of characters per line
2650 (setq cw-min
(/ (* icw fs-min
) ifs
)
2651 nb-cpl-max
(floor (/ print-width cw-min
))
2652 cw-max
(/ (* icw fs-max
) ifs
)
2653 nb-cpl-min
(floor (/ print-width cw-max
))
2656 (goto-char (point-max))
2657 (or (bolp) (insert "\n"))
2659 "nb char per line / font size\n")
2660 (while (<= nb-cpl nb-cpl-max
)
2661 (setq cw
(/ print-width
(float nb-cpl
))
2662 fs
(/ (* ifs cw
) icw
))
2663 (insert (format "%3s %s\n" nb-cpl fs
))
2664 (setq nb-cpl
(1+ nb-cpl
)))
2666 (display-buffer buf
'not-this-window
)))
2668 (defun ps-nb-pages (nb-lines)
2669 "Display correspondence between font size and the number of pages.
2670 The correspondence is based on having NB-LINES lines of text,
2671 and on the current ps-print setup."
2672 (let ((buf (get-buffer-create "*Nb-Pages*"))
2673 (ifs ps-font-size-internal
) ; initial font size
2674 (ilh (ps-line-height 'ps-font-for-text
)) ; initial line height
2675 (page-height (progn (ps-get-page-dimensions)
2677 (ps-setup (ps-setup)) ; setup for the current buffer
2678 (fs-min 4) ; minimum font size
2679 lh-min
; minimum line height
2680 nb-lpp-max
; maximum nb of lines per page
2681 nb-page-min
; minimum nb of pages
2682 (fs-max 14) ; maximum font size
2683 lh-max
; maximum line height
2684 nb-lpp-min
; minimum nb of lines per page
2685 nb-page-max
; maximum nb of pages
2686 fs
; current font size
2687 lh
; current line height
2688 nb-lpp
; current nb of lines per page
2689 nb-page
; current nb of pages
2691 (setq lh-min
(/ (* ilh fs-min
) ifs
)
2692 nb-lpp-max
(floor (/ page-height lh-min
))
2693 nb-page-min
(ceiling (/ (float nb-lines
) nb-lpp-max
))
2694 lh-max
(/ (* ilh fs-max
) ifs
)
2695 nb-lpp-min
(floor (/ page-height lh-max
))
2696 nb-page-max
(ceiling (/ (float nb-lines
) nb-lpp-min
))
2697 nb-page nb-page-min
)
2699 (goto-char (point-max))
2700 (or (bolp) (insert "\n"))
2702 (format "%d lines\n" nb-lines
)
2703 "nb page / font size\n")
2704 (while (<= nb-page nb-page-max
)
2705 (setq nb-lpp
(ceiling (/ nb-lines
(float nb-page
)))
2706 lh
(/ page-height nb-lpp
)
2707 fs
(/ (* ifs lh
) ilh
))
2708 (insert (format "%s %s\n" nb-page fs
))
2709 (setq nb-page
(1+ nb-page
)))
2711 (display-buffer buf
'not-this-window
)))
2713 ;; macros used in `ps-select-font'
2714 (defmacro ps-lookup
(key) `(cdr (assq ,key font-entry
)))
2715 (defmacro ps-size-scale
(key) `(/ (* (ps-lookup ,key
) font-size
) size
))
2717 (defun ps-select-font (font-family sym font-size title-font-size
)
2718 (let ((font-entry (cdr (assq font-family ps-font-info-database
))))
2720 (error "Don't have data to scale font %s. Known fonts families are %s"
2722 (mapcar 'car ps-font-info-database
)))
2723 (let ((size (ps-lookup 'size
)))
2724 (put sym
'fonts
(ps-lookup 'fonts
))
2725 (put sym
'space-width
(ps-size-scale 'space-width
))
2726 (put sym
'avg-char-width
(ps-size-scale 'avg-char-width
))
2727 (put sym
'line-height
(ps-size-scale 'line-height
))
2728 (put sym
'title-line-height
2729 (/ (* (ps-lookup 'line-height
) title-font-size
) size
)))))
2731 (defun ps-get-page-dimensions ()
2732 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
2733 page-width page-height
)
2735 ((null page-dimensions
)
2736 (error "`ps-paper-type' must be one of:\n%s"
2737 (mapcar 'car ps-page-dimensions-database
)))
2738 ((< ps-number-of-columns
1)
2739 (error "The number of columns %d should be positive"
2740 ps-number-of-columns
)))
2742 (ps-select-font ps-font-family
'ps-font-for-text
2743 ps-font-size-internal ps-font-size-internal
)
2744 (ps-select-font ps-header-font-family
'ps-font-for-header
2745 ps-header-font-size-internal
2746 ps-header-title-font-size-internal
)
2748 (setq page-width
(ps-page-dimensions-get-width page-dimensions
)
2749 page-height
(ps-page-dimensions-get-height page-dimensions
))
2752 (if ps-landscape-mode
2753 ;; exchange width and height
2754 (setq page-width
(prog1 page-height
(setq page-height page-width
))))
2756 ;; It is used to get the lower right corner (only in landscape mode)
2757 (setq ps-landscape-page-height page-height
)
2759 ;; | lm | text | ic | text | ic | text | rm |
2760 ;; page-width == lm + n * pw + (n - 1) * ic + rm
2761 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
2762 (setq ps-print-width
(/ (- page-width
2763 ps-left-margin ps-right-margin
2764 (* (1- ps-number-of-columns
) ps-inter-column
))
2765 ps-number-of-columns
))
2766 (if (<= ps-print-width
0)
2767 (error "Bad horizontal layout:
2769 ps-left-margin == %s
2770 ps-right-margin == %s
2771 ps-inter-column == %s
2772 ps-number-of-columns == %s
2773 | lm | text | ic | text | ic | text | rm |
2774 page-width == lm + n * print-width + (n - 1) * ic + rm
2775 => print-width == %d !"
2780 ps-number-of-columns
2783 (setq ps-print-height
2784 (- page-height ps-bottom-margin ps-top-margin
))
2785 (if (<= ps-print-height
0)
2786 (error "Bad vertical layout:
2788 ps-bottom-margin == %s
2789 page-height == bm + print-height + tm
2790 => print-height == %d !"
2794 ;; If headers are turned on, deduct the height of the header from
2795 ;; the print height.
2797 (setq ps-header-pad
(* ps-header-line-pad
2798 (ps-title-line-height 'ps-font-for-header
))
2799 ps-print-height
(- ps-print-height
2802 (ps-title-line-height 'ps-font-for-header
)
2803 (* (ps-line-height 'ps-font-for-header
)
2804 (1- ps-header-lines
))
2806 (if (<= ps-print-height
0)
2807 (error "Bad vertical layout:
2809 ps-bottom-margin == %s
2810 ps-header-offset == %s
2813 page-height == bm + print-height + tm - ho - hh
2814 => print-height == %d !"
2820 (ps-title-line-height 'ps-font-for-header
)
2821 (* (ps-line-height 'ps-font-for-header
)
2822 (1- ps-header-lines
))
2826 (defun ps-print-preprint (&optional filename
)
2828 (or (numberp filename
)
2830 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
2833 (prompt (format "Save PostScript to file: (default %s) " name
))
2834 (res (read-file-name prompt default-directory name nil
)))
2835 (while (cond ((not (file-writable-p res
))
2837 (setq prompt
"is unwritable"))
2838 ((file-exists-p res
)
2839 (setq prompt
"exists")
2840 (not (y-or-n-p (format "File `%s' exists; overwrite? "
2843 (setq res
(read-file-name
2844 (format "File %s; save PostScript to file: " prompt
)
2845 (file-name-directory res
) nil nil
2846 (file-name-nondirectory res
))))
2847 (if (file-directory-p res
)
2848 (expand-file-name name
(file-name-as-directory res
))
2851 ;; The following functions implement a simple list-buffering scheme so
2852 ;; that ps-print doesn't have to repeatedly switch between buffers
2853 ;; while spooling. The functions `ps-output' and `ps-output-string' build
2854 ;; up the lists; the function `ps-flush-output' takes the lists and
2855 ;; insert its contents into the spool buffer (*PostScript*).
2857 (defvar ps-string-escape-codes
2858 (let ((table (make-vector 256 nil
))
2860 ;; control characters
2861 (while (<= char ?
\037)
2862 (aset table char
(format "\\%03o" char
))
2863 (setq char
(1+ char
)))
2864 ;; printable characters
2865 (while (< char ?
\177)
2866 (aset table char
(format "%c" char
))
2867 (setq char
(1+ char
)))
2868 ;; DEL and 8-bit characters
2869 (while (<= char ?
\377)
2870 (aset table char
(format "\\%o" char
))
2871 (setq char
(1+ char
)))
2872 ;; Override ASCII formatting characters with named escape code:
2873 (aset table ?
\n "\\n") ; [NL] linefeed
2874 (aset table ?
\r "\\r") ; [CR] carriage return
2875 (aset table ?
\t "\\t") ; [HT] horizontal tab
2876 (aset table ?
\b "\\b") ; [BS] backspace
2877 (aset table ?
\f "\\f") ; [NP] form feed
2878 ;; Escape PostScript escape and string delimiter characters:
2879 (aset table ?
\\ "\\\\")
2880 (aset table ?\
( "\\(")
2881 (aset table ?\
) "\\)")
2883 "Vector used to map characters to PostScript string escape codes.")
2885 (defun ps-output-string-prim (string)
2886 (insert "(") ;insert start-string delimiter
2887 (save-excursion ;insert string
2888 (insert (string-as-unibyte string
)))
2889 ;; Find and quote special characters as necessary for PS
2890 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
2891 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
2892 (let ((special (following-char)))
2894 (insert (aref ps-string-escape-codes special
))))
2895 (goto-char (point-max))
2896 (insert ")")) ;insert end-string delimiter
2898 (defun ps-init-output-queue ()
2899 (setq ps-output-head
'("")
2900 ps-output-tail ps-output-head
))
2902 (defun ps-output (&rest args
)
2903 (setcdr ps-output-tail args
)
2904 (while (cdr ps-output-tail
)
2905 (setq ps-output-tail
(cdr ps-output-tail
))))
2907 (defun ps-output-string (string)
2908 (ps-output t string
))
2910 (defun ps-output-list (the-list)
2911 (mapcar 'ps-output the-list
))
2913 ;; Output strings in the list ARGS in the PostScript prologue part.
2914 (defun ps-output-prologue (args)
2915 (ps-output 'prologue
(if (stringp args
) (list args
) args
)))
2917 (defun ps-flush-output ()
2919 (set-buffer ps-spool-buffer
)
2920 (goto-char (point-max))
2921 (while ps-output-head
2922 (let ((it (car ps-output-head
)))
2925 (setq ps-output-head
(cdr ps-output-head
))
2926 (ps-output-string-prim (car ps-output-head
)))
2928 (setq ps-output-head
(cdr ps-output-head
))
2930 (search-backward "\nBeginDoc")
2932 (apply 'insert
(car ps-output-head
))))
2935 (setq ps-output-head
(cdr ps-output-head
))))
2936 (ps-init-output-queue))
2938 (defun ps-insert-file (fname)
2940 ;; Check to see that the file exists and is readable; if not, throw
2942 (or (file-readable-p fname
)
2943 (error "Could not read file `%s'" fname
))
2945 (set-buffer ps-spool-buffer
)
2946 (goto-char (point-max))
2947 (insert-file fname
)))
2949 ;; These functions insert the arrays that define the contents of the
2952 (defun ps-generate-header-line (fonttag &optional content
)
2953 (ps-output " [ " fonttag
" ")
2955 ;; Literal strings should be output as is -- the string must
2956 ;; contain its own PS string delimiters, '(' and ')', if necessary.
2958 (ps-output content
))
2960 ;; Functions are called -- they should return strings; they will be
2961 ;; inserted as strings and the PS string delimiters added.
2962 ((and (symbolp content
) (fboundp content
))
2963 (ps-output-string (funcall content
)))
2965 ;; Variables will have their contents inserted. They should
2966 ;; contain strings, and will be inserted as strings.
2967 ((and (symbolp content
) (boundp content
))
2968 (ps-output-string (symbol-value content
)))
2970 ;; Anything else will get turned into an empty string.
2972 (ps-output-string "")))
2975 (defun ps-generate-header (name contents
)
2976 (ps-output "/" name
" [\n")
2977 (if (> ps-header-lines
0)
2979 (ps-generate-header-line "/h0" (car contents
))
2980 (while (and (< count ps-header-lines
)
2981 (setq contents
(cdr contents
)))
2982 (ps-generate-header-line "/h1" (car contents
))
2983 (setq count
(1+ count
)))
2984 (ps-output "] def\n"))))
2987 (defun ps-output-boolean (name bool
&optional no-def
)
2988 (ps-output (format "/%s %s%s"
2989 name
(if bool
"true" "false") (if no-def
"\n" " def\n"))))
2992 (defun ps-background-pages (page-list func
)
2996 (let ((start (if (consp pages
) (car pages
) pages
))
2997 (end (if (consp pages
) (cdr pages
) pages
)))
2998 (and (integerp start
) (integerp end
) (<= start end
)
2999 (add-to-list 'ps-background-pages
(vector start end func
)))))
3001 (setq ps-background-all-pages
(cons func ps-background-all-pages
))))
3004 (defconst ps-boundingbox-re
3006 \\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3009 (defun ps-get-boundingbox ()
3011 (set-buffer ps-spool-buffer
)
3013 (if (re-search-forward ps-boundingbox-re nil t
)
3014 (vector (string-to-number ; lower x
3015 (buffer-substring (match-beginning 1) (match-end 1)))
3016 (string-to-number ; lower y
3017 (buffer-substring (match-beginning 2) (match-end 2)))
3018 (string-to-number ; upper x
3019 (buffer-substring (match-beginning 3) (match-end 3)))
3020 (string-to-number ; upper y
3021 (buffer-substring (match-beginning 4) (match-end 4))))
3022 (vector 0 0 0 0)))))
3025 ;; Emacs understands the %f format; we'll use it to limit color RGB values
3026 ;; to three decimals to cut down some on the size of the PostScript output.
3027 ;; Lucid emacsen will have to make do with %s (princ) for floats.
3029 (defvar ps-float-format
(if (eq ps-print-emacs-type
'emacs
)
3031 "%s ")) ; Lucid emacsen
3034 (defun ps-float-format (value &optional default
)
3035 (let ((literal (or value default
)))
3037 (format (if (numberp literal
)
3044 (defun ps-background-text ()
3047 (setq ps-background-text-count
(1+ ps-background-text-count
))
3048 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count
))
3049 (ps-output-string (nth 0 text
)) ; text
3052 (ps-float-format (nth 4 text
) 200.0) ; font size
3053 (format "/%s " (or (nth 3 text
) "Times-Roman")) ; font name
3054 (ps-float-format (nth 6 text
)
3055 "PrintHeight PrintPageWidth atan") ; rotation
3056 (ps-float-format (nth 5 text
) 0.85) ; gray
3057 (ps-float-format (nth 1 text
) "0") ; x position
3058 (ps-float-format (nth 2 text
) "BottomMargin") ; y position
3059 "\nShowBackText} def\n")
3060 (ps-background-pages (nthcdr 7 text
) ; page list
3061 (format "ShowBackText-%d\n"
3062 ps-background-text-count
)))
3063 ps-print-background-text
))
3066 (defun ps-background-image ()
3069 (let ((image-file (expand-file-name (nth 0 image
))))
3070 (when (file-readable-p image-file
)
3071 (setq ps-background-image-count
(1+ ps-background-image-count
))
3073 (format "/ShowBackImage-%d {\n--back-- "
3074 ps-background-image-count
)
3075 (ps-float-format (nth 5 image
) 0.0) ; rotation
3076 (ps-float-format (nth 3 image
) 1.0) ; x scale
3077 (ps-float-format (nth 4 image
) 1.0) ; y scale
3078 (ps-float-format (nth 1 image
) ; x position
3079 "PrintPageWidth 2 div")
3080 (ps-float-format (nth 2 image
) ; y position
3081 "PrintHeight 2 div BottomMargin add")
3082 "\nBeginBackImage\n")
3083 (ps-insert-file image-file
)
3084 ;; coordinate adjustment to centralize image
3085 ;; around x and y position
3086 (let ((box (ps-get-boundingbox)))
3088 (set-buffer ps-spool-buffer
)
3090 (if (re-search-backward "^--back--" nil t
)
3094 (- (+ (/ (- (aref box
2) (aref box
0)) 2.0)
3097 (- (+ (/ (- (aref box
3) (aref box
1)) 2.0)
3100 (ps-output "\nEndBackImage} def\n")
3101 (ps-background-pages (nthcdr 6 image
) ; page list
3102 (format "ShowBackImage-%d\n"
3103 ps-background-image-count
)))))
3104 ps-print-background-image
))
3107 (defun ps-background (page-number)
3108 (let (has-local-background)
3109 (mapcar #'(lambda (range)
3110 (and (<= (aref range
0) page-number
)
3111 (<= page-number
(aref range
1))
3112 (if has-local-background
3113 (ps-output (aref range
2))
3114 (setq has-local-background t
)
3115 (ps-output "/printLocalBackground {\n"
3117 ps-background-pages
)
3118 (and has-local-background
(ps-output "} def\n"))))
3121 ;; Return a list of the distinct elements of LIST.
3122 ;; Elements are compared with `equal'.
3123 (defun ps-remove-duplicates (list)
3124 (let (new (tail list
))
3126 (or (member (car tail
) new
)
3127 (setq new
(cons (car tail
) new
)))
3128 (setq tail
(cdr tail
)))
3132 ;; Find the first occurrence of ITEM in LIST.
3133 ;; Return the index of the matching item, or nil if not found.
3134 ;; Elements are compared with `eq'.
3135 (defun ps-alist-position (item list
)
3136 (let ((tail list
) (index 0) found
)
3138 (if (setq found
(eq (car (car tail
)) item
))
3140 (setq index
(1+ index
)
3145 (defconst ps-n-up-database
3282 ;; Ledger paper size is a special case, it is the only paper size where the
3283 ;; normal size is landscaped, that is, the height is smaller than width.
3284 ;; So, we use the special value `pag' in the `landscape' field.
3428 "Alist which is the page matrix database used for N-up printing.
3430 Each element has the following form:
3433 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
3437 PAGE is the page size used (see `ps-paper-type').
3438 MAX is the maximum elements of this page matrix.
3439 LANDSCAPE specifies if page matrix is landscaped, has the following valid
3441 nil the sheet is in portrait mode.
3442 t the sheet is in landscape mode.
3443 pag the sheet is in portrait mode and page is in landscape mode.
3444 LINES is the number of lines of page matrix.
3445 COLUMNS is the number of columns of page matrix.
3446 COL-MISSING is the number of columns missing to fill the sheet.")
3449 (defmacro ps-n-up-landscape
(mat) `(nth 1 ,mat
))
3450 (defmacro ps-n-up-lines
(mat) `(nth 2 ,mat
))
3451 (defmacro ps-n-up-columns
(mat) `(nth 3 ,mat
))
3452 (defmacro ps-n-up-missing
(mat) `(nth 4 ,mat
))
3455 (defun ps-n-up-printing ()
3456 ;; force `ps-n-up-printing' be in range 1 to 100.
3457 (setq ps-n-up-printing
(max (min ps-n-up-printing
100) 1))
3458 ;; find suitable page matrix for a given `ps-paper-type'.
3459 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database
))))
3461 (while (> ps-n-up-printing
(caar the-list
))
3462 (setq the-list
(cdr the-list
))))
3466 (defconst ps-n-up-filling-database
3468 "PageWidth" ; N-Up-XColumn
3470 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3471 "LandscapePageHeight neg" ; N-Up-YLine
3472 "N-Up-Lines" ; N-Up-Repeat
3473 "N-Up-Columns" ; N-Up-End
3477 "PageWidth" ; N-Up-XColumn
3479 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3480 "LandscapePageHeight" ; N-Up-YLine
3481 "N-Up-Lines" ; N-Up-Repeat
3482 "N-Up-Columns" ; N-Up-End
3484 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3486 "PageWidth neg" ; N-Up-XColumn
3488 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3489 "LandscapePageHeight neg" ; N-Up-YLine
3490 "N-Up-Lines" ; N-Up-Repeat
3491 "N-Up-Columns" ; N-Up-End
3492 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3495 "PageWidth neg" ; N-Up-XColumn
3497 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3498 "LandscapePageHeight" ; N-Up-YLine
3499 "N-Up-Lines" ; N-Up-Repeat
3500 "N-Up-Columns" ; N-Up-End
3501 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3502 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3505 "LandscapePageHeight neg" ; N-Up-YColumn
3506 "PageWidth" ; N-Up-XLine
3507 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3508 "N-Up-Columns" ; N-Up-Repeat
3509 "N-Up-Lines" ; N-Up-End
3514 "LandscapePageHeight" ; N-Up-YColumn
3515 "PageWidth" ; N-Up-XLine
3516 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3517 "N-Up-Columns" ; N-Up-Repeat
3518 "N-Up-Lines" ; N-Up-End
3520 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3523 "LandscapePageHeight neg" ; N-Up-YColumn
3524 "PageWidth neg" ; N-Up-XLine
3525 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3526 "N-Up-Columns" ; N-Up-Repeat
3527 "N-Up-Lines" ; N-Up-End
3528 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3532 "LandscapePageHeight" ; N-Up-YColumn
3533 "PageWidth neg" ; N-Up-XLine
3534 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3535 "N-Up-Columns" ; N-Up-Repeat
3536 "N-Up-Lines" ; N-Up-End
3537 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3538 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
3539 "Alist for n-up printing initializations.
3541 Each element has the following form:
3543 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
3546 KIND is a valid value of `ps-n-up-filling'.
3547 XCOL YCOL are the relative position for the next column.
3548 XLIN YLIN are the relative position for the beginning of next line.
3549 REPEAT is the number of repetions for external loop.
3550 END is the number of repetions for internal loop and also the number of pages in
3552 XSTART YSTART are the relative position for the first page in a sheet.")
3555 (defun ps-n-up-filling ()
3556 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database
)
3557 (assq 'left-top ps-n-up-filling-database
))))
3560 (defmacro ps-n-up-xcolumn
(init) `(nth 0 ,init
))
3561 (defmacro ps-n-up-ycolumn
(init) `(nth 1 ,init
))
3562 (defmacro ps-n-up-xline
(init) `(nth 2 ,init
))
3563 (defmacro ps-n-up-yline
(init) `(nth 3 ,init
))
3564 (defmacro ps-n-up-repeat
(init) `(nth 4 ,init
))
3565 (defmacro ps-n-up-end
(init) `(nth 5 ,init
))
3566 (defmacro ps-n-up-xstart
(init) `(nth 6 ,init
))
3567 (defmacro ps-n-up-ystart
(init) `(nth 7 ,init
))
3570 (defun ps-begin-file ()
3571 (ps-get-page-dimensions)
3572 (setq ps-page-postscript
0
3574 ps-background-text-count
0
3575 ps-background-image-count
0
3576 ps-background-pages nil
3577 ps-background-all-pages nil
)
3579 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database
)))
3580 (tumble (if ps-landscape-mode
(not ps-spool-tumble
) ps-spool-tumble
))
3581 (n-up (ps-n-up-printing))
3582 (n-up-filling (ps-n-up-filling)))
3583 (and (> ps-n-up-printing
1) (setq tumble
(not tumble
)))
3586 "%%Title: " (buffer-name) ; Take job name from name of
3587 ; first buffer printed
3588 "\n%%Creator: " (user-full-name)
3589 " (using ps-print v" ps-print-version
3590 ")\n%%CreationDate: "
3591 (time-stamp-hh:mm
:ss
) " " (time-stamp-mon-dd-yyyy)
3593 (if ps-landscape-mode
"Landscape" "Portrait")
3594 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
3595 (mapconcat 'identity
3596 (ps-remove-duplicates
3597 (append (ps-fonts 'ps-font-for-text
)
3598 (list (ps-font 'ps-font-for-header
'normal
)
3599 (ps-font 'ps-font-for-header
'bold
))))
3601 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions
)
3602 (format " %d" (round (ps-page-dimensions-get-width dimensions
)))
3603 (format " %d" (round (ps-page-dimensions-get-height dimensions
)))
3604 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
3606 (format " duplex%s" (if tumble
"(tumble)\n" "\n"))
3609 (let ((comments (if (functionp ps-print-prologue-header
)
3610 (funcall ps-print-prologue-header
)
3611 ps-print-prologue-header
)))
3612 (and (stringp comments
)
3613 (ps-output comments
)))
3615 (ps-output "%%EndComments\n\n%%BeginPrologue\n\n"
3616 "/gs_languagelevel /languagelevel where "
3617 "{pop languagelevel}{1}ifelse def\n\n")
3619 (ps-output-boolean "SkipFirstPage " ps-banner-page-when-duplexing
)
3620 (ps-output-boolean "LandscapeMode "
3621 (or ps-landscape-mode
3622 (eq (ps-n-up-landscape n-up
) 'pag
)))
3623 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns
)
3625 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height
)
3626 (format "/PrintPageWidth %s def\n"
3627 (- (* (+ ps-print-width ps-inter-column
)
3628 ps-number-of-columns
)
3630 (format "/PrintWidth %s def\n" ps-print-width
)
3631 (format "/PrintHeight %s def\n" ps-print-height
)
3633 (format "/LeftMargin %s def\n" ps-left-margin
)
3634 (format "/RightMargin %s def\n" ps-right-margin
)
3635 (format "/InterColumn %s def\n" ps-inter-column
)
3637 (format "/BottomMargin %s def\n" ps-bottom-margin
)
3638 (format "/TopMargin %s def\n" ps-top-margin
) ; not used
3639 (format "/HeaderOffset %s def\n" ps-header-offset
)
3640 (format "/HeaderPad %s def\n" ps-header-pad
))
3642 (ps-output-boolean "PrintHeader " ps-print-header
)
3643 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header
)
3644 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame
)
3645 (ps-output-boolean "ShowNofN " ps-show-n-of-n
)
3646 (ps-output-boolean "DuplexValue " ps-spool-duplex
)
3647 (ps-output-boolean "TumbleValue " tumble
)
3649 (let ((line-height (ps-line-height 'ps-font-for-text
)))
3650 (ps-output (format "/LineHeight %s def\n" line-height
)
3651 (format "/LinesPerColumn %d def\n"
3652 (round (/ (+ ps-print-height
3653 (* line-height
0.45))
3656 (ps-output-boolean "Zebra " ps-zebra-stripes
)
3657 (ps-output-boolean "PrintLineNumber " ps-line-number
)
3658 (ps-output (format "/ZebraHeight %d def\n" ps-zebra-stripe-height
)
3659 (format "/ZebraGray %s def\n" ps-zebra-gray
)
3660 "/UseSetpagedevice "
3661 (if (eq ps-spool-config
'setpagedevice
)
3662 "/setpagedevice where {pop true}{false}ifelse def\n"
3665 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
3666 (format "/N-Up %d def\n" ps-n-up-printing
))
3667 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up
) t
))
3668 (ps-output-boolean "N-Up-Border " ps-n-up-border-p
)
3669 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up
))
3670 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up
))
3671 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up
))
3672 (format "/N-Up-Margin %s" ps-n-up-margin
)
3673 " def\n/N-Up-Repeat "
3674 (if ps-landscape-mode
3675 (ps-n-up-end n-up-filling
)
3676 (ps-n-up-repeat n-up-filling
))
3678 (if ps-landscape-mode
3679 (ps-n-up-repeat n-up-filling
)
3680 (ps-n-up-end n-up-filling
))
3681 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling
)
3682 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling
)
3683 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling
)
3684 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling
)
3685 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling
)
3686 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling
) " def\n")
3688 (ps-background-text)
3689 (ps-background-image)
3690 (setq ps-background-all-pages
(nreverse ps-background-all-pages
)
3691 ps-background-pages
(nreverse ps-background-pages
))
3693 (ps-output "\n" ps-print-prologue-1
)
3695 (ps-output "\n/printGlobalBackground {\n")
3696 (ps-output-list ps-background-all-pages
)
3697 (ps-output "} def\n/printLocalBackground {\n} def\n")
3700 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
3701 ps-header-title-font-size-internal
3702 (ps-font 'ps-font-for-header
'bold
))
3703 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
3704 ps-header-font-size-internal
3705 (ps-font 'ps-font-for-header
'normal
)))
3707 (ps-output "\n" ps-print-prologue-2
"\n")
3710 (let ((font (ps-font-alist 'ps-font-for-text
))
3713 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
3715 ps-font-size-internal
3716 (ps-font 'ps-font-for-text
(car (car font
)))))
3717 (setq font
(cdr font
)
3720 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database
))))
3721 (ps-output (format "/SpaceWidthRatio %f def\n"
3722 (/ (ps-lookup 'space-width
) (ps-lookup 'size
)))))
3724 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
3725 (unless (eq ps-spool-config
'lpr-switches
)
3726 (ps-output "\n%%BeginFeature: *Duplex "
3727 (ps-boolean-capitalized ps-spool-duplex
)
3729 (ps-boolean-capitalized tumble
)
3731 ps-print-duplex-feature
3732 "\n%%EndFeature\n")))
3733 (ps-output "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n"))
3736 (defun ps-boolean-capitalized (bool)
3737 (if bool
"True" "False"))
3740 (defun ps-header-dirpart ()
3741 (let ((fname (buffer-file-name)))
3743 (if (string-equal (buffer-name) (file-name-nondirectory fname
))
3744 (abbreviate-file-name (file-name-directory fname
))
3749 (defun ps-get-buffer-name ()
3751 ;; Indulge Jim this little easter egg:
3752 ((string= (buffer-name) "ps-print.el")
3753 "Hey, Cool! It's ps-print.el!!!")
3754 ;; Indulge Jack this other little easter egg:
3755 ((string= (buffer-name) "sokoban.el")
3756 "Super! C'est sokoban.el!")
3758 (and ps-printing-region-p
"Subset of: ")
3760 (and (buffer-modified-p) " (unsaved)")))))
3763 (defun ps-get-font-size (font-sym)
3764 (let ((font-size (symbol-value font-sym
)))
3765 (cond ((numberp font-size
)
3767 ((and (consp font-size
)
3768 (numberp (car font-size
))
3769 (numberp (cdr font-size
)))
3770 (if ps-landscape-mode
3774 (error "Invalid font size `%S' for `%S'" font-size font-sym
)))))
3777 (defun ps-begin-job ()
3778 (or (equal ps-mark-code-directory ps-postscript-code-directory
)
3779 (setq ps-print-prologue-1
(ps-prologue-file 1)
3780 ps-print-prologue-2
(ps-prologue-file 2)
3781 ps-print-duplex-feature
(ps-prologue-file 3)
3782 ps-mark-code-directory ps-postscript-code-directory
))
3784 (set-buffer ps-spool-buffer
)
3785 (goto-char (point-max))
3786 (and (re-search-backward "^%%Trailer$" nil t
)
3787 (delete-region (match-beginning 0) (point-max))))
3788 (setq ps-showline-count
(car ps-printing-region
)
3790 ps-font-size-internal
(ps-get-font-size 'ps-font-size
)
3791 ps-header-font-size-internal
(ps-get-font-size 'ps-header-font-size
)
3792 ps-header-title-font-size-internal
3793 (ps-get-font-size 'ps-header-title-font-size
)
3794 ps-control-or-escape-regexp
3795 (cond ((eq ps-print-control-characters
'8-bit
)
3796 (string-as-unibyte "[\000-\037\177-\377]"))
3797 ((eq ps-print-control-characters
'control-8-bit
)
3798 (string-as-unibyte "[\000-\037\177-\237]"))
3799 ((eq ps-print-control-characters
'control
)
3803 (defmacro ps-page-number
()
3804 `(1+ (/ (1- ps-page-count
) ps-number-of-columns
)))
3806 (defun ps-end-file ()
3807 ;; Back to the PS output buffer to set the last page n-up printing
3809 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing
))
3811 (set-buffer ps-spool-buffer
)
3812 (goto-char (point-max))
3813 (and (> pages-per-sheet
0)
3814 (re-search-backward "^[0-9]+ BeginSheet$" nil t
)
3815 (replace-match (format "%d BeginSheet" pages-per-sheet
) t
))))
3817 (and ps-spool-duplex
(= (mod ps-page-order
2) 1)
3819 ;; Set end of PostScript file
3820 (ps-output "EndSheet\n\n%%Trailer\n%%Pages: "
3821 (format "%d" ps-page-order
)
3822 "\n\nEndDoc\n\n%%EOF\n"))
3825 (defun ps-next-page ()
3831 (defun ps-header-sheet ()
3832 ;; Print only when a new sheet begins.
3833 (setq ps-page-postscript
(1+ ps-page-postscript
)
3834 ps-page-order
(1+ ps-page-order
))
3835 (and (> ps-page-order
1)
3836 (ps-output "EndSheet\n"))
3837 (ps-output (format "\n%%%%Page: %d %d\n"
3838 ps-page-postscript ps-page-order
))
3839 (ps-output (format "%d BeginSheet\nBeginDSCPage\n" ps-n-up-printing
)))
3842 (defsubst ps-header-page
()
3843 ;; set total line and page number when printing has finished
3844 ;; (see `ps-generate')
3847 (zerop (mod ps-page-count ps-number-of-columns
))
3848 (setq ps-page-count
(1+ ps-page-count
)))
3850 (if (zerop (mod ps-page-postscript ps-n-up-printing
))
3851 ;; Print only when a new sheet begins.
3854 'ps-print-begin-sheet-hook
)
3855 ;; Print only when a new page begins.
3856 (setq ps-page-postscript
(1+ ps-page-postscript
))
3857 (ps-output "BeginDSCPage\n")
3858 'ps-print-begin-page-hook
)
3859 (ps-background ps-page-postscript
))
3860 ;; Print only when a new column begins.
3861 (ps-output "BeginDSCPage\n")
3862 'ps-print-begin-column-hook
)))
3864 (defun ps-begin-page ()
3865 (ps-get-page-dimensions)
3866 (setq ps-width-remaining ps-print-width
3867 ps-height-remaining ps-print-height
)
3871 (ps-output (format "/LineNumber %d def\n" ps-showline-count
)
3872 (format "/PageNumber %d def\n" (if ps-print-only-one-header
3876 (when ps-print-header
3877 (ps-generate-header "HeaderLinesLeft" ps-left-header
)
3878 (ps-generate-header "HeaderLinesRight" ps-right-header
)
3879 (ps-output (format "%d SetHeaderLines\n" ps-header-lines
)))
3881 (ps-output "BeginPage\n")
3882 (ps-set-font ps-current-font
)
3883 (ps-set-bg ps-current-bg
)
3884 (ps-set-color ps-current-color
)
3885 (ps-mule-begin-page))
3887 (defun ps-end-page ()
3888 (ps-output "EndPage\nEndDSCPage\n"))
3890 (defun ps-dummy-page ()
3891 (let ((ps-n-up-printing 0))
3893 (ps-output "/PrintHeader false def
3895 /PrintLineNumber false def
3899 (setq ps-page-postscript ps-n-up-printing
))
3901 (defun ps-next-line ()
3902 (setq ps-showline-count
(1+ ps-showline-count
))
3903 (let ((lh (ps-line-height 'ps-font-for-text
)))
3904 (if (< ps-height-remaining lh
)
3906 (setq ps-width-remaining ps-print-width
3907 ps-height-remaining
(- ps-height-remaining lh
))
3908 (ps-output "HL\n"))))
3910 (defun ps-continue-line ()
3911 (let ((lh (ps-line-height 'ps-font-for-text
)))
3912 (if (< ps-height-remaining lh
)
3914 (setq ps-width-remaining ps-print-width
3915 ps-height-remaining
(- ps-height-remaining lh
))
3916 (ps-output "SL\n"))))
3918 (defun ps-find-wrappoint (from to char-width
)
3919 (let ((avail (truncate (/ ps-width-remaining char-width
)))
3922 (cons to
(* todo char-width
))
3923 (cons (+ from avail
) ps-width-remaining
))))
3925 (defun ps-basic-plot-string (from to
&optional bg-color
)
3926 (let* ((wrappoint (ps-find-wrappoint from to
3927 (ps-avg-char-width 'ps-font-for-text
)))
3928 (to (car wrappoint
))
3929 (string (buffer-substring-no-properties from to
)))
3930 (ps-mule-prepare-ascii-font string
)
3931 (ps-output-string string
)
3935 (defun ps-basic-plot-whitespace (from to
&optional bg-color
)
3936 (let* ((wrappoint (ps-find-wrappoint from to
3937 (ps-space-width 'ps-font-for-text
)))
3938 (to (car wrappoint
)))
3939 (ps-output (format "%d W\n" (- to from
)))
3942 (defun ps-plot (plotfunc from to
&optional bg-color
)
3944 (let* ((wrappoint (funcall plotfunc from to bg-color
))
3945 (plotted-to (car wrappoint
))
3946 (plotted-width (cdr wrappoint
)))
3947 (setq from plotted-to
3948 ps-width-remaining
(- ps-width-remaining plotted-width
))
3950 (ps-continue-line))))
3951 (if ps-razzle-dazzle
3952 (let* ((q-todo (- (point-max) (point-min)))
3953 (q-done (- (point) (point-min)))
3954 (chunkfrac (/ q-todo
8))
3955 (chunksize (min chunkfrac
1000)))
3956 (if (> (- q-done ps-razchunk
) chunksize
)
3958 (setq ps-razchunk q-done
)
3959 (message "Formatting...%3d%%"
3961 (/ (* 100 q-done
) q-todo
)
3962 (/ q-done
(/ q-todo
100)))
3965 (defvar ps-last-font nil
)
3967 (defun ps-set-font (font)
3968 (setq ps-last-font
(format "f%d" (setq ps-current-font font
)))
3969 (ps-output (format "/%s F\n" ps-last-font
)))
3971 (defun ps-set-bg (color)
3972 (if (setq ps-current-bg color
)
3973 (ps-output (format ps-color-format
3974 (nth 0 color
) (nth 1 color
) (nth 2 color
))
3976 (ps-output "false BG\n")))
3978 (defun ps-set-color (color)
3979 (setq ps-current-color
(or color ps-default-fg
))
3980 (ps-output (format ps-color-format
3981 (nth 0 ps-current-color
)
3982 (nth 1 ps-current-color
) (nth 2 ps-current-color
))
3986 (defvar ps-current-effect
0)
3989 (defun ps-plot-region (from to font
&optional fg-color bg-color effects
)
3990 (if (not (equal font ps-current-font
))
3993 ;; Specify a foreground color only if one's specified and it's
3994 ;; different than the current.
3995 (if (not (equal fg-color ps-current-color
))
3996 (ps-set-color fg-color
))
3998 (if (not (equal bg-color ps-current-bg
))
3999 (ps-set-bg bg-color
))
4001 ;; Specify effects (underline, overline, box, etc)
4003 ((not (integerp effects
))
4004 (ps-output "0 EF\n")
4005 (setq ps-current-effect
0))
4006 ((/= effects ps-current-effect
)
4007 (ps-output (number-to-string effects
) " EF\n")
4008 (setq ps-current-effect effects
)))
4010 ;; Starting at the beginning of the specified region...
4014 ;; ...break the region up into chunks separated by tabs, linefeeds,
4015 ;; pagefeeds, control characters, and plot each chunk.
4017 (if (re-search-forward ps-control-or-escape-regexp to t
)
4018 ;; region with some control characters or some multi-byte characters
4019 (let* ((match-point (match-beginning 0))
4020 (match (char-after match-point
))
4021 (composition (find-composition from
(1+ match-point
))))
4023 (if (and (nth 2 composition
)
4024 (<= (car composition
) match-point
))
4026 (setq match-point
(car composition
)
4028 (goto-char (nth 1 composition
)))
4029 (setq composition nil
)))
4030 (when (< from match-point
)
4031 (ps-mule-set-ascii-font)
4032 (ps-plot 'ps-basic-plot-string from match-point bg-color
))
4034 ((= match ?
\t) ; tab
4035 (let ((linestart (line-beginning-position)))
4037 (setq from
(+ linestart
(current-column)))
4038 (when (re-search-forward "[ \t]+" to t
)
4039 (ps-mule-set-ascii-font)
4040 (ps-plot 'ps-basic-plot-whitespace
4041 from
(+ linestart
(current-column))
4044 ((= match ?
\n) ; newline
4047 ((= match ?
\f) ; form feed
4048 ;; do not skip page if previous character is NEWLINE and
4049 ;; it is a beginning of page.
4050 (or (and (= (char-after (1- match-point
)) ?
\n)
4051 (= ps-height-remaining ps-print-height
))
4054 (composition ; a composite sequence
4055 (ps-plot 'ps-mule-plot-composition match-point
(point) bg-color
))
4057 ; characters from ^@ to ^_ and
4058 ((> match
255) ; a multi-byte character
4059 (let* ((charset (char-charset match
))
4060 (composition (find-composition match-point to
))
4061 (stop (if (nth 2 composition
) (car composition
) to
)))
4062 (or (eq charset
'composition
)
4063 (while (and (< (point) stop
) (eq (charset-after) charset
))
4065 (ps-plot 'ps-mule-plot-string match-point
(point) bg-color
)))
4067 (t ; characters from 127 to 255
4068 (ps-control-character match
)))
4069 (setq from
(point)))
4070 ;; region without control characters nor multi-byte characters
4071 (ps-mule-set-ascii-font)
4072 (ps-plot 'ps-basic-plot-string from to bg-color
)
4075 (defvar ps-string-control-codes
4076 (let ((table (make-vector 256 nil
))
4078 ;; control character
4079 (while (<= char ?
\037)
4080 (aset table char
(format "^%c" (+ char ?
@)))
4081 (setq char
(1+ char
)))
4082 ;; printable character
4083 (while (< char ?
\177)
4084 (aset table char
(format "%c" char
))
4085 (setq char
(1+ char
)))
4087 (aset table char
"^?")
4089 (while (<= (setq char
(1+ char
)) ?
\377)
4090 (aset table char
(format "\\%o" char
)))
4092 "Vector used to map characters to a printable string.")
4094 (defun ps-control-character (char)
4095 (let* ((str (aref ps-string-control-codes char
))
4099 (char-width (ps-avg-char-width 'ps-font-for-text
))
4100 (wrappoint (ps-find-wrappoint from to char-width
)))
4101 (if (< (car wrappoint
) to
)
4103 (setq ps-width-remaining
(- ps-width-remaining
(* len char-width
)))
4104 (ps-mule-prepare-ascii-font str
)
4105 (ps-output-string str
)
4106 (ps-output " S\n")))
4108 (defun ps-color-value (x-color-value)
4109 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
4110 (/ x-color-value ps-print-color-scale
))
4113 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4115 (defun ps-color-values (x-color)
4116 (if (fboundp 'x-color-values
)
4117 (x-color-values x-color
)
4118 (error "No available function to determine X color values.")))
4123 (defun ps-color-values (x-color)
4124 (cond ((fboundp 'x-color-values
)
4125 (x-color-values x-color
))
4126 ((and (fboundp 'color-instance-rgb-components
)
4128 (color-instance-rgb-components
4129 (if (color-instance-p x-color
)
4131 (make-color-instance
4132 (if (color-specifier-p x-color
)
4133 (color-name x-color
)
4136 (error "No available function to determine X color values."))))
4140 (defun ps-face-attributes (face)
4141 "Return face attribute vector.
4143 If FACE is not in `ps-print-face-extension-alist' or in
4144 `ps-print-face-alist', insert it on `ps-print-face-alist' and
4145 return the attribute vector.
4147 If FACE is not a valid face name, it is used default face."
4148 (cdr (or (assq face ps-print-face-extension-alist
)
4149 (assq face ps-print-face-alist
)
4150 (let* ((the-face (if (facep face
) face
'default
))
4151 (new-face (ps-screen-to-bit-face the-face
)))
4152 (or (and (eq the-face
'default
)
4153 (assq the-face ps-print-face-alist
))
4154 (setq ps-print-face-alist
(cons new-face ps-print-face-alist
)))
4158 (defun ps-face-attribute-list (face-or-list)
4159 (if (listp face-or-list
)
4162 foreground background face-attr
)
4164 (setq face-attr
(ps-face-attributes (car face-or-list
))
4165 effects
(logior effects
(aref face-attr
0)))
4166 (or foreground
(setq foreground
(aref face-attr
1)))
4167 (or background
(setq background
(aref face-attr
2)))
4168 (setq face-or-list
(cdr face-or-list
)))
4169 (vector effects foreground background
))
4171 (ps-face-attributes face-or-list
)))
4174 (defconst ps-font-type
(vector nil
'bold
'italic
'bold-italic
))
4177 (defun ps-plot-with-face (from to face
)
4179 ((null face
) ; print text with null face
4180 (ps-plot-region from to
0))
4181 ((eq face
'emacs--invisible--face
)) ; skip invisible text!!!
4182 (t ; otherwise, text has a valid face
4183 (let* ((face-bit (ps-face-attribute-list face
))
4184 (effect (aref face-bit
0))
4185 (foreground (aref face-bit
1))
4186 (background (aref face-bit
2))
4187 (fg-color (if (and ps-color-p foreground
)
4188 (mapcar 'ps-color-value
4189 (ps-color-values foreground
))
4191 (bg-color (and ps-color-p background
4192 (mapcar 'ps-color-value
4193 (ps-color-values background
)))))
4196 (ps-font-number 'ps-font-for-text
4197 (or (aref ps-font-type
(logand effect
3))
4199 fg-color bg-color
(lsh effect -
2)))))
4203 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list
)
4204 (let* ((frame-font (or (face-font-instance face
)
4205 (face-font-instance 'default
)))
4206 (kind-cons (and frame-font
4208 (font-instance-properties frame-font
))))
4209 (kind-spec (cdr-safe kind-cons
))
4210 (case-fold-search t
))
4211 (or (and kind-spec
(string-match kind-regex kind-spec
))
4212 ;; Kludge-compatible:
4213 (memq face kind-list
))))
4216 (cond ((eq ps-print-emacs-type
'emacs
) ; emacs
4218 (defun ps-face-bold-p (face)
4219 (or (face-bold-p face
)
4220 (memq face ps-bold-faces
)))
4222 (defun ps-face-italic-p (face)
4223 (or (face-italic-p face
)
4224 (memq face ps-italic-faces
)))
4229 (defun ps-face-bold-p (face)
4230 (ps-xemacs-face-kind-p face
'WEIGHT_NAME
"bold\\|demibold"
4233 (defun ps-face-italic-p (face)
4234 (or (ps-xemacs-face-kind-p face
'ANGLE_NAME
"i\\|o" ps-italic-faces
)
4235 (ps-xemacs-face-kind-p face
'SLANT
"i\\|o" ps-italic-faces
)))
4239 (defun ps-face-underlined-p (face)
4240 (or (face-underline-p face
)
4241 (memq face ps-underlined-faces
)))
4244 ;; Ensure that face-list is fbound.
4245 (or (fboundp 'face-list
) (defalias 'face-list
'list-faces
))
4248 (defun ps-build-reference-face-lists ()
4249 ;; Ensure that face database is updated with faces on
4250 ;; `font-lock-face-attributes' (obsolete stuff)
4251 (ps-font-lock-face-attributes)
4252 ;; Now, rebuild reference face lists
4253 (setq ps-print-face-alist nil
)
4254 (if ps-auto-font-detect
4255 (mapcar 'ps-map-face
(face-list))
4256 (mapcar 'ps-set-face-bold ps-bold-faces
)
4257 (mapcar 'ps-set-face-italic ps-italic-faces
)
4258 (mapcar 'ps-set-face-underline ps-underlined-faces
))
4259 (setq ps-build-face-reference nil
))
4262 (defun ps-set-face-bold (face)
4263 (ps-set-face-attribute face
1))
4265 (defun ps-set-face-italic (face)
4266 (ps-set-face-attribute face
2))
4268 (defun ps-set-face-underline (face)
4269 (ps-set-face-attribute face
4))
4272 (defun ps-set-face-attribute (face effect
)
4273 (let ((face-bit (cdr (ps-map-face face
))))
4274 (aset face-bit
0 (logior (aref face-bit
0) effect
))))
4277 (defun ps-map-face (face)
4278 (let* ((face-map (ps-screen-to-bit-face face
))
4279 (ps-face-bit (cdr (assq (car face-map
) ps-print-face-alist
))))
4281 ;; if face exists, merge both
4282 (let ((face-bit (cdr face-map
)))
4283 (aset ps-face-bit
0 (logior (aref ps-face-bit
0) (aref face-bit
0)))
4284 (or (aref ps-face-bit
1) (aset ps-face-bit
1 (aref face-bit
1)))
4285 (or (aref ps-face-bit
2) (aset ps-face-bit
2 (aref face-bit
2))))
4286 ;; if face does not exist, insert it
4287 (setq ps-print-face-alist
(cons face-map ps-print-face-alist
)))
4291 (defun ps-screen-to-bit-face (face)
4293 (vector (logior (if (ps-face-bold-p face
) 1 0) ; bold
4294 (if (ps-face-italic-p face
) 2 0) ; italic
4295 (if (ps-face-underlined-p face
) 4 0)) ; underline
4296 (face-foreground face
)
4297 (face-background face
))))
4300 (cond ((not (eq ps-print-emacs-type
'emacs
))
4304 (defun ps-mapper (extent list
)
4305 (nconc list
(list (list (extent-start-position extent
) 'push extent
)
4306 (list (extent-end-position extent
) 'pull extent
)))
4309 (defun ps-extent-sorter (a b
)
4310 (< (extent-priority a
) (extent-priority b
)))
4314 (defun ps-print-ensure-fontified (start end
)
4315 (and (boundp 'lazy-lock-mode
) (symbol-value 'lazy-lock-mode
)
4316 (lazy-lock-fontify-region start end
)))
4318 (defun ps-generate-postscript-with-faces (from to
)
4319 ;; Some initialization...
4320 (setq ps-current-effect
0)
4322 ;; Build the reference lists of faces if necessary.
4323 (if (or ps-always-build-face-reference
4324 ps-build-face-reference
)
4326 (message "Collecting face information...")
4327 (ps-build-reference-face-lists)))
4328 ;; Set the color scale. We do it here instead of in the defvar so
4329 ;; that ps-print can be dumped into emacs. This expression can't be
4330 ;; evaluated at dump-time because X isn't initialized.
4331 (setq ps-color-p
(and ps-print-color-p
(ps-color-device))
4332 ps-print-color-scale
(if ps-color-p
4333 (float (car (ps-color-values "white")))
4335 ;; Generate some PostScript.
4337 (narrow-to-region from to
)
4338 (ps-print-ensure-fontified from to
)
4339 (let ((face 'default
)
4342 ((or (eq ps-print-emacs-type
'lucid
)
4343 (eq ps-print-emacs-type
'xemacs
))
4344 ;; Build the list of extents...
4345 (let ((a (cons 'dummy nil
))
4346 record type extent extent-list
)
4347 (map-extents 'ps-mapper nil from to a
)
4348 (setq a
(sort (cdr a
) 'car-less-than-car
)
4351 ;; Loop through the extents...
4353 (setq record
(car a
)
4355 position
(car record
)
4361 extent
(car record
))
4363 ;; Plot up to this record.
4364 ;; XEmacs 19.12: for some reason, we're getting into a
4365 ;; situation in which some of the records have
4366 ;; positions less than 'from'. Since we've narrowed
4367 ;; the buffer, this'll generate errors. This is a
4368 ;; hack, but don't call ps-plot-with-face unless from >
4370 (and (>= from
(point-min)) (<= position
(point-max))
4371 (ps-plot-with-face from position face
))
4375 (and (extent-face extent
)
4376 (setq extent-list
(sort (cons extent extent-list
)
4377 'ps-extent-sorter
))))
4380 (setq extent-list
(sort (delq extent extent-list
)
4381 'ps-extent-sorter
))))
4383 (setq face
(if extent-list
4384 (extent-face (car extent-list
))
4389 ((eq ps-print-emacs-type
'emacs
)
4390 (let ((property-change from
)
4391 (overlay-change from
)
4392 (save-buffer-invisibility-spec buffer-invisibility-spec
)
4393 (buffer-invisibility-spec nil
))
4395 (and (< property-change to
) ; Don't search for property change
4396 ; unless previous search succeeded.
4397 (setq property-change
(next-property-change from nil to
)))
4398 (and (< overlay-change to
) ; Don't search for overlay change
4399 ; unless previous search succeeded.
4400 (setq overlay-change
(min (next-overlay-change from
) to
)))
4401 (setq position
(min property-change overlay-change
))
4402 ;; The code below is not quite correct,
4403 ;; because a non-nil overlay invisible property
4404 ;; which is inactive according to the current value
4405 ;; of buffer-invisibility-spec nonetheless overrides
4406 ;; a face text property.
4408 (cond ((let ((prop (get-text-property from
'invisible
)))
4409 ;; Decide whether this invisible property
4410 ;; really makes the text invisible.
4411 (if (eq save-buffer-invisibility-spec t
)
4413 (or (memq prop save-buffer-invisibility-spec
)
4414 (assq prop save-buffer-invisibility-spec
))))
4415 'emacs--invisible--face
)
4416 ((get-text-property from
'face
))
4418 (let ((overlays (overlays-at from
))
4419 (face-priority -
1)) ; text-property
4420 (while (and overlays
4421 (not (eq face
'emacs--invisible--face
)))
4422 (let* ((overlay (car overlays
))
4423 (overlay-invisible (overlay-get overlay
'invisible
))
4424 (overlay-priority (or (overlay-get overlay
'priority
)
4426 (and (> overlay-priority face-priority
)
4428 (cond ((if (eq save-buffer-invisibility-spec t
)
4429 (not (null overlay-invisible
))
4430 (or (memq overlay-invisible
4431 save-buffer-invisibility-spec
)
4432 (assq overlay-invisible
4433 save-buffer-invisibility-spec
)))
4434 'emacs--invisible--face
)
4435 ((overlay-get overlay
'face
))
4437 face-priority overlay-priority
)))
4438 (setq overlays
(cdr overlays
))))
4439 ;; Plot up to this record.
4440 (ps-plot-with-face from position face
)
4441 (setq from position
)))))
4442 (ps-plot-with-face from to face
))))
4444 (defun ps-generate-postscript (from to
)
4445 (ps-plot-region from to
0 nil
))
4447 (defun ps-generate (buffer from to genfunc
)
4449 (let ((from (min to from
))
4451 ;; This avoids trouble if chars with read-only properties
4452 ;; are copied into ps-spool-buffer.
4453 (inhibit-read-only t
))
4455 (narrow-to-region from to
)
4456 (and ps-razzle-dazzle
4457 (message "Formatting...%3d%%" (setq ps-razchunk
0)))
4458 (setq ps-source-buffer buffer
4459 ps-spool-buffer
(get-buffer-create ps-spool-buffer-name
))
4460 (ps-init-output-queue)
4461 (let (safe-marker completed-safely needs-begin-file
)
4464 (set-buffer ps-spool-buffer
)
4465 (set-buffer-multibyte nil
)
4467 ;; Get a marker and make it point to the current end of the
4468 ;; buffer, If an error occurs, we'll delete everything from
4469 ;; the end of this marker onwards.
4470 (setq safe-marker
(make-marker))
4471 (set-marker safe-marker
(point-max))
4473 (goto-char (point-min))
4474 (or (looking-at (regexp-quote ps-adobe-tag
))
4475 (setq needs-begin-file t
))
4477 (set-buffer ps-source-buffer
)
4479 (when needs-begin-file
4481 (ps-mule-initialize))
4482 (ps-mule-begin-job from to
)
4484 (set-buffer ps-source-buffer
)
4485 (funcall genfunc from to
)
4492 ;; Setting this variable tells the unwind form that the
4493 ;; the PostScript was generated without error.
4494 (setq completed-safely t
))
4496 ;; Unwind form: If some bad mojo occurred while generating
4497 ;; PostScript, delete all the PostScript that was generated.
4498 ;; This protects the previously spooled files from getting
4500 (and (markerp safe-marker
) (not completed-safely
)
4502 (set-buffer ps-spool-buffer
)
4503 (delete-region (marker-position safe-marker
) (point-max))))))
4505 (and ps-razzle-dazzle
(message "Formatting...done"))))))
4508 (defun ps-end-job ()
4509 (let ((total-lines (cdr ps-printing-region
))
4510 (total-pages (if ps-print-only-one-header
4514 (set-buffer ps-spool-buffer
)
4515 ;; Back to the PS output buffer to set the page count
4516 (goto-char (point-min))
4517 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t
)
4518 (replace-match (format "/Lines %d def\n/PageCount %d def"
4519 total-lines total-pages
) t
))))
4522 ;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
4523 (defun ps-do-despool (filename)
4524 (if (or (not (boundp 'ps-spool-buffer
))
4525 (not (symbol-value 'ps-spool-buffer
)))
4526 (message "No spooled PostScript to print")
4529 (and ps-razzle-dazzle
(message "Saving..."))
4530 (set-buffer ps-spool-buffer
)
4531 (setq filename
(expand-file-name filename
))
4532 (let ((coding-system-for-write 'raw-text-unix
))
4533 (write-region (point-min) (point-max) filename
))
4534 (and ps-razzle-dazzle
(message "Wrote %s" filename
)))
4535 ;; Else, spool to the printer
4536 (and ps-razzle-dazzle
(message "Printing..."))
4538 (set-buffer ps-spool-buffer
)
4539 (let* ((coding-system-for-write 'raw-text-unix
)
4540 (ps-printer-name (or ps-printer-name
4541 (and (boundp 'printer-name
)
4544 (append (and (stringp ps-printer-name
)
4545 (list (concat "-P" ps-printer-name
)))
4547 (apply (or ps-print-region-function
'call-process-region
)
4548 (point-min) (point-max) ps-lpr-command nil
4549 (and (fboundp 'start-process
) 0)
4551 (ps-flatten-list ; dynamic evaluation
4552 (mapcar 'ps-eval-switch ps-lpr-switches
)))))
4553 (and ps-razzle-dazzle
(message "Printing...done")))
4554 (kill-buffer ps-spool-buffer
)))
4556 ;; Dynamic evaluation
4557 (defun ps-eval-switch (arg)
4558 (cond ((stringp arg
) arg
)
4559 ((functionp arg
) (apply arg nil
))
4560 ((symbolp arg
) (symbol-value arg
))
4561 ((consp arg
) (apply (car arg
) (cdr arg
)))
4564 ;; `ps-flatten-list' is defined here (copied from "message.el" and
4565 ;; enhanced to handle dotted pairs as well) until we can get some
4566 ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
4568 ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
4569 ;; => (a b c d e f g h i j)
4571 (defun ps-flatten-list (&rest list
)
4572 (ps-flatten-list-1 list
))
4574 (defun ps-flatten-list-1 (list)
4575 (cond ((null list
) nil
)
4576 ((consp list
) (append (ps-flatten-list-1 (car list
))
4577 (ps-flatten-list-1 (cdr list
))))
4580 (defun ps-kill-emacs-check ()
4582 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
4583 (buffer-modified-p ps-buffer
)
4584 (y-or-n-p "Unprinted PostScript waiting; print now? ")
4586 (and (setq ps-buffer
(get-buffer ps-spool-buffer-name
))
4587 (buffer-modified-p ps-buffer
)
4588 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
4589 (error "Unprinted PostScript"))))
4591 (cond ((fboundp 'add-hook
)
4592 (funcall 'add-hook
'kill-emacs-hook
'ps-kill-emacs-check
))
4594 (message "Won't override existing `kill-emacs-hook'"))
4596 (setq kill-emacs-hook
'ps-kill-emacs-check
)))
4599 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4600 ;;; Sample Setup Code:
4603 ;; This stuff is for anybody that's brave enough to look this far,
4604 ;; and able to figure out how to use it. It isn't really part of
4605 ;; ps-print, but I'll leave it here in hopes it might be useful:
4607 ;; WARNING!!! The following code is *sample* code only.
4608 ;; Don't use it unless you understand what it does!
4610 (defmacro ps-prsc
()
4611 `(if (eq ps-print-emacs-type
'emacs
) [f22] 'f22))
4612 (defmacro ps-c-prsc ()
4613 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
4614 (defmacro ps-s-prsc ()
4615 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
4617 ;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
4618 ;; `ps-left-headers' specially for mail messages.
4619 (defun ps-rmail-mode-hook ()
4620 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
4621 (setq ps-header-lines 3
4623 ;; The left headers will display the message's subject, its
4624 ;; author, and the name of the folder it was in.
4625 '(ps-article-subject ps-article-author buffer-name)))
4627 ;; See `ps-gnus-print-article-from-summary'. This function does the
4628 ;; same thing for rmail.
4629 (defun ps-rmail-print-message-from-summary ()
4631 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
4633 ;; Used in `ps-rmail-print-article-from-summary',
4634 ;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
4635 (defun ps-print-message-from-summary (summary-buffer summary-default)
4636 (let ((ps-buf (or (and (boundp summary-buffer)
4637 (symbol-value summary-buffer))
4639 (and (get-buffer ps-buf)
4642 (ps-spool-buffer-with-faces)))))
4644 ;; Look in an article or mail message for the Subject: line. To be
4645 ;; placed in `ps-left-headers'.
4646 (defun ps-article-subject ()
4648 (goto-char (point-min))
4649 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
4650 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4653 ;; Look in an article or mail message for the From: line. Sorta-kinda
4654 ;; understands RFC-822 addresses and can pull the real name out where
4655 ;; it's provided. To be placed in `ps-left-headers'.
4656 (defun ps-article-author ()
4658 (goto-char (point-min))
4659 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
4660 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
4664 ;; Try first to match addresses that look like
4665 ;; thompson@wg2.waii.com (Jim Thompson)
4666 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
4667 (substring fromstring (match-beginning 1) (match-end 1)))
4669 ;; Next try to match addresses that look like
4670 ;; Jim Thompson <thompson@wg2.waii.com>
4671 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
4672 (substring fromstring (match-beginning 1) (match-end 1)))
4674 ;; Couldn't find a real name -- show the address instead.
4678 ;; A hook to bind to `gnus-article-prepare-hook'. This will set the
4679 ;; `ps-left-headers' specially for gnus articles. Unfortunately,
4680 ;; `gnus-article-mode-hook' is called only once, the first time the *Article*
4681 ;; buffer enters that mode, so it would only work for the first time
4682 ;; we ran gnus. The second time, this hook wouldn't get set up. The
4683 ;; only alternative is `gnus-article-prepare-hook'.
4684 (defun ps-gnus-article-prepare-hook ()
4685 (setq ps-header-lines 3
4687 ;; The left headers will display the article's subject, its
4688 ;; author, and the newsgroup it was in.
4689 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
4691 ;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
4692 ;; `ps-left-headers' specially for mail messages.
4693 (defun ps-vm-mode-hook ()
4694 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
4695 (setq ps-header-lines 3
4697 ;; The left headers will display the message's subject, its
4698 ;; author, and the name of the folder it was in.
4699 '(ps-article-subject ps-article-author buffer-name)))
4701 ;; Every now and then I forget to switch from the *Summary* buffer to
4702 ;; the *Article* before hitting prsc, and a nicely formatted list of
4703 ;; article subjects shows up at the printer. This function, bound to
4704 ;; prsc for the gnus *Summary* buffer means I don't have to switch
4706 ;; sb: Updated for Gnus 5.
4707 (defun ps-gnus-print-article-from-summary ()
4709 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
4711 ;; See `ps-gnus-print-article-from-summary'. This function does the
4712 ;; same thing for vm.
4713 (defun ps-vm-print-message-from-summary ()
4715 (ps-print-message-from-summary 'vm-mail-buffer ""))
4717 ;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
4719 (defun ps-gnus-summary-setup ()
4720 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
4722 ;; Look in an article or mail message for the Subject: line. To be
4723 ;; placed in `ps-left-headers'.
4724 (defun ps-info-file ()
4726 (goto-char (point-min))
4727 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
4728 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4731 ;; Look in an article or mail message for the Subject: line. To be
4732 ;; placed in `ps-left-headers'.
4733 (defun ps-info-node ()
4735 (goto-char (point-min))
4736 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
4737 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
4740 (defun ps-info-mode-hook ()
4741 (setq ps-left-header
4742 ;; The left headers will display the node name and file name.
4743 '(ps-info-node ps-info-file)))
4745 ;; WARNING! The following function is a *sample* only, and is *not*
4746 ;; meant to be used as a whole unless you understand what the effects
4747 ;; will be! (In fact, this is a copy of Jim's setup for ps-print --
4748 ;; I'd be very surprised if it was useful to *anybody*, without
4751 (defun ps-jts-ps-setup ()
4752 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
4753 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
4754 (global-set-key (ps-c-prsc) 'ps-despool)
4755 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
4756 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
4757 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
4758 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
4759 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
4760 (setq ps-spool-duplex t
4761 ps-print-color-p nil
4762 ps-lpr-command "lpr"
4763 ps-lpr-switches '("-Jjct,duplex_long"))
4766 ;; WARNING! The following function is a *sample* only, and is *not*
4767 ;; meant to be used as a whole unless it corresponds to your needs.
4768 ;; (In fact, this is a copy of Jack's setup for ps-print --
4769 ;; I would not be that surprised if it was useful to *anybody*,
4770 ;; without modification.)
4772 (defun ps-jack-setup ()
4773 (setq ps-print-color-p nil
4774 ps-lpr-command "lpr"
4779 ps-number-of-columns 2
4781 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
4782 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
4783 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
4784 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
4785 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
4786 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
4787 ps-header-line-pad .15
4789 ps-print-header-frame t
4794 ps-font-family 'Courier
4796 ps-header-font-family 'Helvetica
4797 ps-header-font-size 6
4798 ps-header-title-font-size 8)
4802 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4803 ;; To make this file smaller, some commands go in a separate file.
4804 ;; But autoload them here to make the separation invisible.
4806 (autoload 'ps-mule-prepare-ascii-font "ps-mule"
4807 "Setup special ASCII font for STRING.
4808 STRING should contain only ASCII characters.")
4810 (autoload 'ps-mule-set-ascii-font "ps-mule"
4811 "Adjust current font if current charset is not ASCII.")
4813 (autoload 'ps-mule-plot-string "ps-mule"
4814 "Generate PostScript code for ploting characters in the region FROM and TO.
4816 It is assumed that all characters in this region belong to the same charset.
4818 Optional argument BG-COLOR specifies background color.
4822 (ENDPOS . RUN-WIDTH)
4824 Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
4827 (autoload 'ps-mule-initialize "ps-mule"
4828 "Initialize global data for printing multi-byte characters.")
4830 (autoload 'ps-mule-begin-job "ps-mule"
4831 "Start printing job for multi-byte chars between FROM and TO.
4832 This checks if all multi-byte characters in the region are printable or not.")
4834 (autoload 'ps-mule-begin-page "ps-mule"
4835 "Initialize multi-byte charset for printing current page.")
4838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4842 ;;; ps-print.el ends here