(msb-menu-cond): Add choice `user'.
[bpt/emacs.git] / lisp / ps-print.el
CommitLineData
535efc38 1;;; ps-print.el --- Print text from the buffer as PostScript
12d89a2e 2
66e63857 3;; Copyright (C) 1993-2000 Free Software Foundation, Inc.
ef2cbb24 4
e65df0a1 5;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
024ced4d 6;; Author: Jacques Duthen (was <duthen@cegelec-red.fr>)
e65df0a1 7;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
024ced4d
KH
8;; Author: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
9;; Maintainer: Kenichi Handa <handa@etl.go.jp> (multi-byte characters)
e65df0a1 10;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
bc0d41bd 11;; Keywords: wp, print, PostScript
906d41a7
GM
12;; Time-stamp: <2000/04/24 12:23:14 vinicius>
13;; Version: 5.2
e65df0a1 14
906d41a7
GM
15(defconst ps-print-version "5.2"
16 "ps-print.el, v 5.2 <2000/04/24 vinicius>
090be653 17
535efc38 18Vinicius's last change version -- this file may have been edited as part of
906d41a7
GM
19Emacs without changes to the version number. When reporting bugs, please also
20report the version of Emacs, if any, that ps-print was distributed with.
090be653
RS
21
22Please send all bug fixes and enhancements to
8bd22fcf 23 Vinicius Jose Latorre <vinicius@cpqd.com.br>.
090be653 24")
ef2cbb24 25
86c10ecb 26;; This file is part of GNU Emacs.
ef2cbb24
RS
27
28;; GNU Emacs is free software; you can redistribute it and/or modify
29;; it under the terms of the GNU General Public License as published by
30;; the Free Software Foundation; either version 2, or (at your option)
31;; any later version.
32
33;; GNU Emacs is distributed in the hope that it will be useful,
34;; but WITHOUT ANY WARRANTY; without even the implied warranty of
35;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36;; GNU General Public License for more details.
37
38;; You should have received a copy of the GNU General Public License
b578f267
EN
39;; along with GNU Emacs; see the file COPYING. If not, write to the
40;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41;; Boston, MA 02111-1307, USA.
ef2cbb24 42
12d89a2e 43;;; Commentary:
ef2cbb24 44
bc0d41bd 45;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ef2cbb24 46;;
12d89a2e 47;; About ps-print
ef2cbb24 48;; --------------
bcc0d457 49;;
0a5daee5
KH
50;; This package provides printing of Emacs buffers on PostScript printers;
51;; the buffer's bold and italic text attributes are preserved in the printer
52;; output. ps-print is intended for use with Emacs or Lucid Emacs, together
53;; with a fontifying package such as font-lock or hilit.
12d89a2e 54;;
87a16a06
RS
55;; ps-print uses the same face attributes defined through font-lock or hilit
56;; to print a PostScript file, but some faces are better seeing on the screen
57;; than on paper, specially when you have a black/white PostScript printer.
58;;
59;; ps-print allows a remap of face to another one that it is better to print,
60;; for example, the face font-lock-comment-face (if you are using font-lock)
61;; could have bold or italic attribute when printing, besides foreground color.
62;; This remap improves printing look (see How Ps-Print Maps Faces).
63;;
bcc0d457 64;;
12d89a2e 65;; Using ps-print
ef2cbb24 66;; --------------
ef2cbb24 67;;
d3ab8dac 68;; ps-print provides eight commands for generating PostScript images
12d89a2e
RS
69;; of Emacs buffers:
70;;
71;; ps-print-buffer
72;; ps-print-buffer-with-faces
73;; ps-print-region
74;; ps-print-region-with-faces
75;; ps-spool-buffer
76;; ps-spool-buffer-with-faces
77;; ps-spool-region
78;; ps-spool-region-with-faces
79;;
80;; These commands all perform essentially the same function: they
81;; generate PostScript images suitable for printing on a PostScript
82;; printer or displaying with GhostScript. These commands are
83;; collectively referred to as "ps-print- commands".
84;;
85;; The word "print" or "spool" in the command name determines when the
86;; PostScript image is sent to the printer:
ef2cbb24 87;;
12d89a2e
RS
88;; print - The PostScript image is immediately sent to the
89;; printer;
ef2cbb24 90;;
12d89a2e
RS
91;; spool - The PostScript image is saved temporarily in an
92;; Emacs buffer. Many images may be spooled locally
93;; before printing them. To send the spooled images
bcc0d457 94;; to the printer, use the command `ps-despool'.
ef2cbb24 95;;
12d89a2e
RS
96;; The spooling mechanism was designed for printing lots of small
97;; files (mail messages or netnews articles) to save paper that would
98;; otherwise be wasted on banner pages, and to make it easier to find
99;; your output at the printer (it's easier to pick up one 50-page
100;; printout than to find 50 single-page printouts).
06fb6aab 101;;
d3ab8dac 102;; ps-print has a hook in the `kill-emacs-hook' so that you won't
a7acbbe4 103;; accidentally quit from Emacs while you have unprinted PostScript
12d89a2e
RS
104;; waiting in the spool buffer. If you do attempt to exit with
105;; spooled PostScript, you'll be asked if you want to print it, and if
106;; you decline, you'll be asked to confirm the exit; this is modeled
107;; on the confirmation that Emacs uses for modified buffers.
108;;
109;; The word "buffer" or "region" in the command name determines how
110;; much of the buffer is printed:
111;;
112;; buffer - Print the entire buffer.
113;;
114;; region - Print just the current region.
115;;
116;; The -with-faces suffix on the command name means that the command
117;; will include font, color, and underline information in the
118;; PostScript image, so the printed image can look as pretty as the
119;; buffer. The ps-print- commands without the -with-faces suffix
120;; don't include font, color, or underline information; images printed
121;; with these commands aren't as pretty, but are faster to generate.
122;;
123;; Two ps-print- command examples:
124;;
125;; ps-print-buffer - print the entire buffer,
126;; without font, color, or
127;; underline information, and
128;; send it immediately to the
129;; printer.
130;;
131;; ps-spool-region-with-faces - print just the current region;
132;; include font, color, and
133;; underline information, and
134;; spool the image in Emacs to
135;; send to the printer later.
136;;
137;;
138;; Invoking Ps-Print
bcc0d457 139;; -----------------
ef2cbb24 140;;
12d89a2e 141;; To print your buffer, type
ef2cbb24 142;;
12d89a2e 143;; M-x ps-print-buffer
ef2cbb24 144;;
12d89a2e
RS
145;; or substitute one of the other seven ps-print- commands. The
146;; command will generate the PostScript image and print or spool it as
147;; specified. By giving the command a prefix argument
148;;
149;; C-u M-x ps-print-buffer
150;;
151;; it will save the PostScript image to a file instead of sending it
152;; to the printer; you will be prompted for the name of the file to
153;; save the image to. The prefix argument is ignored by the commands
154;; that spool their images, but you may save the spooled images to a
bcc0d457 155;; file by giving a prefix argument to `ps-despool':
12d89a2e
RS
156;;
157;; C-u M-x ps-despool
158;;
bcc0d457 159;; When invoked this way, `ps-despool' will prompt you for the name of
12d89a2e
RS
160;; the file to save to.
161;;
bcc0d457
RS
162;; Any of the `ps-print-' commands can be bound to keys; I recommend
163;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
164;; and `ps-despool'. Here are the bindings I use on my Sun 4 keyboard:
12d89a2e
RS
165;;
166;; (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
ef2cbb24
RS
167;; (global-set-key '(shift f22) 'ps-spool-region-with-faces)
168;; (global-set-key '(control f22) 'ps-despool)
169;;
12d89a2e
RS
170;;
171;; The Printer Interface
bcc0d457 172;; ---------------------
12d89a2e 173;;
bcc0d457 174;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
12d89a2e 175;; command is used to send the PostScript images to the printer, and
bcc0d457
RS
176;; what arguments to give the command. These are analogous to
177;; `lpr-command' and `lpr-switches'.
87a16a06 178;;
bcc0d457
RS
179;; Make sure that they contain appropriate values for your system;
180;; see the usage notes below and the documentation of these variables.
181;;
bc0d41bd 182;; The variable `ps-printer-name' determines the name of a local printer for
d3ab8dac
KH
183;; printing PostScript files.
184;;
bcc0d457
RS
185;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
186;; from the variables `lpr-command' and `lpr-switches'. If you have
187;; `lpr-command' set to invoke a pretty-printer such as `enscript',
188;; then ps-print won't work properly. `ps-lpr-command' must name
12d89a2e 189;; a program that does not format the files it prints.
d3ab8dac
KH
190;; `ps-printer-name' takes its initial value from the variable
191;; `printer-name'.
12d89a2e 192;;
bc0d41bd
KH
193;; The variable `ps-print-region-function' specifies a function to print the
194;; region on a PostScript printer.
195;; See definition of `call-process-region' for calling conventions. The fourth
196;; and the sixth arguments are both nil.
197;;
edc9cd35
GM
198;; If you're using NTEmacs, don't forget to customize the following variables:
199;; `ps-printer-name', `ps-lpr-command', `ps-lpr-switches' and
200;; `ps-spool-config'. See these variables documentation in the code or by
201;; typing, for example, C-h v ps-printer-name RET.
202;;
12d89a2e 203;;
bcc0d457
RS
204;; The Page Layout
205;; ---------------
12d89a2e 206;;
bcc0d457
RS
207;; All dimensions are floats in PostScript points.
208;; 1 inch == 2.54 cm == 72 points
209;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
12d89a2e 210;;
906d41a7
GM
211;; The variable `ps-paper-type' determines the size of paper ps-print formats
212;; for; it should contain one of the symbols: `a4' `a3' `letter' `legal'
213;; `letter-small' `tabloid' `ledger' `statement' `executive' `a4small' `b4'
214;; `b5'.
12d89a2e 215;;
906d41a7
GM
216;; The variable `ps-landscape-mode' determines the orientation of the printing
217;; on the page: nil means `portrait' mode, non-nil means `landscape' mode.
bcc0d457 218;; There is no oblique mode yet, though this is easy to do in ps.
87a16a06 219;;
906d41a7
GM
220;; In landscape mode, the text is NOT scaled: you may print 70 lines in portrait
221;; mode and only 50 lines in landscape mode. The margins represent margins in
222;; the printed paper: the top margin is the margin between the top of the page
bcc0d457 223;; and the printed header, whatever the orientation is.
043620f4 224;;
906d41a7
GM
225;; The variable `ps-number-of-columns' determines the number of columns both in
226;; landscape and portrait mode.
bcc0d457 227;; You can use:
906d41a7
GM
228;; - (the standard) one column portrait mode.
229;; - (my favorite) two columns landscape mode (which spares trees).
230;; but also:
bcc0d457 231;; - one column landscape mode for files with very long lines.
906d41a7
GM
232;; - multi-column portrait or landscape mode.
233;;
234;; The variable `ps-print-upside-down' determines other orientation for printing
235;; page: nil means `normal' printing, non-nil means `upside-down' printing. The
236;; default value is nil (`normal' printing).
237;;
238;; The `upside-down' orientation can be used in portrait or landscape mode.
12d89a2e 239;;
12d89a2e 240;;
bcc0d457
RS
241;; Horizontal layout
242;; -----------------
12d89a2e 243;;
bcc0d457
RS
244;; The horizontal layout is determined by the variables
245;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
246;; as follows:
12d89a2e 247;;
bcc0d457
RS
248;; ------------------------------------------
249;; | | | | | | | |
250;; | lm | text | ic | text | ic | text | rm |
251;; | | | | | | | |
252;; ------------------------------------------
12d89a2e 253;;
bcc0d457
RS
254;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
255;; Usually, lm = rm > 0 and ic = lm
256;; If (ic < 0), the text of adjacent columns can overlap.
12d89a2e 257;;
12d89a2e 258;;
bcc0d457
RS
259;; Vertical layout
260;; ---------------
261;;
262;; The vertical layout is determined by the variables
263;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
264;; as follows:
265;;
266;; |--------| |--------|
267;; | tm | | tm |
268;; |--------| |--------|
269;; | header | | |
270;; |--------| | |
271;; | ho | | |
272;; |--------| or | text |
273;; | | | |
274;; | text | | |
275;; | | | |
276;; |--------| |--------|
277;; | bm | | bm |
278;; |--------| |--------|
279;;
280;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
281;; The margins represent margins in the printed paper:
282;; the top margin is the margin between the top of the page
283;; and the printed header, whatever the orientation is.
12d89a2e
RS
284;;
285;;
286;; Headers
bcc0d457 287;; -------
12d89a2e 288;;
d3ab8dac 289;; ps-print can print headers at the top of each column or at the top
12b88fff
RS
290;; of each page; the default headers contain the following four items:
291;; on the left, the name of the buffer and, if the buffer is visiting
292;; a file, the file's directory; on the right, the page number and
293;; date of printing. The default headers look something like this:
12d89a2e
RS
294;;
295;; ps-print.el 1/21
296;; /home/jct/emacs-lisp/ps/new 94/12/31
06fb6aab 297;;
12d89a2e 298;; When printing on duplex printers, left and right are reversed so
bcc0d457 299;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
12d89a2e 300;;
bcc0d457
RS
301;; Headers are configurable:
302;; To turn them off completely, set `ps-print-header' to nil.
303;; To turn off the header's gaudy framing box,
304;; set `ps-print-header-frame' to nil.
305;;
12b88fff
RS
306;; To print only one header at the top of each page,
307;; set `ps-print-only-one-header' to t.
308;;
bcc0d457 309;; The font family and size of text in the header are determined
06fb6aab 310;; by the variables `ps-header-font-family', `ps-header-font-size' and
bcc0d457
RS
311;; `ps-header-title-font-size' (see below).
312;;
313;; The variable `ps-header-line-pad' determines the portion of a header
314;; title line height to insert between the header frame and the text
315;; it contains, both in the vertical and horizontal directions:
316;; .5 means half a line.
317
318;; Page numbers are printed in `n/m' format, indicating page n of m pages;
319;; to omit the total page count and just print the page number,
320;; set `ps-show-n-of-n' to nil.
12d89a2e
RS
321;;
322;; The amount of information in the header can be changed by changing
bcc0d457 323;; the number of lines. To show less, set `ps-header-lines' to 1, and
12d89a2e 324;; the header will show only the buffer name and page number. To show
bcc0d457 325;; more, set `ps-header-lines' to 3, and the header will show the time of
12d89a2e
RS
326;; printing below the date.
327;;
328;; To change the content of the headers, change the variables
bcc0d457
RS
329;; `ps-left-header' and `ps-right-header'.
330;; These variables are lists, specifying top-to-bottom the text
331;; to display on the left or right side of the header.
332;; Each element of the list should be a string or a symbol.
333;; Strings are inserted directly into the PostScript arrays,
334;; and should contain the PostScript string delimiters '(' and ')'.
12d89a2e
RS
335;;
336;; Symbols in the header format lists can either represent functions
337;; or variables. Functions are called, and should return a string to
338;; show in the header. Variables should contain strings to display in
339;; the header. In either case, function or variable, the PostScript
a7acbbe4 340;; string delimiters are added by ps-print, and should not be part of
12d89a2e
RS
341;; the returned value.
342;;
343;; Here's an example: say we want the left header to display the text
344;;
345;; Moe
346;; Larry
347;; Curly
348;;
349;; where we have a function to return "Moe"
350;;
351;; (defun moe-func ()
352;; "Moe")
353;;
354;; a variable specifying "Larry"
355;;
356;; (setq larry-var "Larry")
357;;
bcc0d457 358;; and a literal for "Curly". Here's how `ps-left-header' should be
12d89a2e
RS
359;; set:
360;;
361;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
362;;
363;; Note that Curly has the PostScript string delimiters inside his
bcc0d457 364;; quotes -- those aren't misplaced lisp delimiters!
87a16a06 365;;
bcc0d457
RS
366;; Without them, PostScript would attempt to call the undefined
367;; function Curly, which would result in a PostScript error.
87a16a06 368;;
bcc0d457
RS
369;; Since most printers don't report PostScript errors except by
370;; aborting the print job, this kind of error can be hard to track down.
87a16a06 371;;
bcc0d457 372;; Consider yourself warned!
12d89a2e
RS
373;;
374;;
d3ab8dac
KH
375;; PostScript Prologue Header
376;; --------------------------
377;;
378;; It is possible to add PostScript prologue header comments besides that
379;; ps-print generates by setting the variable `ps-print-prologue-header'.
380;;
bc0d41bd
KH
381;; `ps-print-prologue-header' may be a string or a symbol function which returns
382;; a string. Note that this string is inserted on PostScript prologue header
383;; section which is used to define some document characteristic through
d3ab8dac
KH
384;; PostScript special comments, like "%%Requirements: jog\n".
385;;
386;; By default `ps-print-prologue-header' is nil.
387;;
388;; ps-print always inserts the %%Requirements: comment, so if you need to insert
389;; more requirements put them first in `ps-print-prologue-header' using the
390;; "%%+" comment. For example, if you need to set numcopies to 3 and jog on
391;; requirements and set %%LanguageLevel: to 2, do:
392;;
393;; (setq ps-print-prologue-header
394;; "%%+ numcopies(3) jog\n%%LanguageLevel: 2\n")
395;;
396;; The duplex requirement is inserted by ps-print (see section Duplex Printers).
397;;
398;; Do not forget to terminate the string with "\n".
399;;
400;; For more information about PostScript document comments, see:
401;; PostScript Language Reference Manual (2nd edition)
402;; Adobe Systems Incorporated
403;; Appendix G: Document Structuring Conventions -- Version 3.0
404;;
66e63857
GM
405;; It is also possible to add an user defined PostScript prologue code before
406;; all generated prologue code by setting the variable
407;; `ps-user-defined-prologue'.
408;;
409;; `ps-user-defined-prologue' may be a string or a symbol function which returns
410;; a string. Note that this string is inserted after `ps-adobe-tag' and
411;; PostScript prologue comments, and before ps-print PostScript prologue code
412;; section. That is, this string is inserted after error handler initialization
413;; and before ps-print settings.
414;;
415;; By default `ps-user-defined-prologue' is nil.
416;;
417;; It's recommended to initiate and terminate the string with "\n".
418;;
419;; It's strongly recommended only insert PostScript code and/or comments
420;; specific for your printing system particularities. For example, some special
421;; initialization that only your printing system needs.
422;;
423;; Do not insert code for duplex printing, n-up printing or error handler,
424;; ps-print handles this in a suitable way.
425;;
426;; For more information about PostScript, see:
427;; PostScript Language Reference Manual (2nd edition)
428;; Adobe Systems Incorporated
429;;
430;;
431;; PostScript Error Handler
432;; ------------------------
433;;
434;; ps-print instruments generated PostScript code with an error handler.
435;;
436;; The variable `ps-error-handler-message' specifies where the error handler
437;; message should be sent.
438;;
439;; Valid values are:
440;;
441;; none catch the error and *DON'T* send any message.
442;;
443;; paper catch the error and print on paper the error message.
444;; This is the default value.
445;;
446;; system catch the error and send back the error message to
6e1b1da6
GM
447;; printing system. This is useful only if printing system
448;; send back an email reporting the error, or if there is
449;; some other alternative way to report back the error from
450;; the system to you.
66e63857
GM
451;;
452;; paper-and-system catch the error, print on paper the error message and
453;; send back the error message to printing system.
454;;
455;; Any other value is treated as `paper'.
456;;
d3ab8dac 457;;
12d89a2e 458;; Duplex Printers
bcc0d457 459;; ---------------
12d89a2e 460;;
bc0d41bd
KH
461;; If you have a duplex-capable printer (one that prints both sides of the
462;; paper), set `ps-spool-duplex' to t.
463;; ps-print will insert blank pages to make sure each buffer starts on the
464;; correct side of the paper.
465;;
466;; The variable `ps-spool-config' specifies who is the responsable for setting
467;; duplex and page size switches. Valid values are:
468;;
469;; lpr-switches duplex and page size are configured by `ps-lpr-switches'.
470;; Don't forget to set `ps-lpr-switches' to select duplex
471;; printing for your printer.
472;;
473;; setpagedevice duplex and page size are configured by ps-print using the
474;; setpagedevice PostScript operator.
475;;
476;; nil duplex and page size are configured by ps-print *not* using
477;; the setpagedevice PostScript operator.
478;;
479;; Any other value is treated as nil.
480;;
481;; The default value is `lpr-switches'.
482;;
483;; WARNING: The setpagedevice PostScript operator affects ghostview utility when
484;; viewing file generated using landscape. Also on some printers,
485;; setpagedevice affects zebra stripes; on other printers,
486;; setpagedevice affects the left margin.
487;; Besides all that, if your printer does not have the paper size
488;; specified by setpagedevice, your printing will be aborted.
489;; So, if you need to use setpagedevice, set `ps-spool-config' to
490;; `setpagedevice', generate a test file and send it to your printer;
491;; if the printed file isn't ok, set `ps-spool-config' to nil.
492;;
493;; The variable `ps-spool-tumble' specifies how the page images on opposite
494;; sides of a sheet are oriented with respect to each other. If
495;; `ps-spool-tumble' is nil, produces output suitable for binding on the left or
496;; right. If `ps-spool-tumble' is non-nil, produces output suitable for binding
497;; at the top or bottom. It has effect only when `ps-spool-duplex' is non-nil.
498;; The default value is nil.
499;;
500;; Some printer system prints a header page and forces the first page be printed
501;; on header page back, when using duplex. If your printer system has this
502;; behavior, set variable `ps-banner-page-when-duplexing' to t.
503;;
504;; When `ps-banner-page-when-duplexing' is non-nil means the very first page is
505;; skipped. It's like the very first character of buffer (or region) is ^L
506;; (\014).
507;;
508;; The default for `ps-banner-page-when-duplexing' is nil (*don't* skip the very
509;; first page).
510;;
511;;
512;; N-up Printing
513;; -------------
514;;
515;; The variable `ps-n-up-printing' specifies the number of pages per sheet of
516;; paper. The value specified must be between 1 and 100. The default is 1.
517;;
518;; NOTE: some PostScript printer may crash printing if `ps-n-up-printing' is set
519;; to a high value (for example, 23). If this happens, set a lower value.
520;;
521;; The variable `ps-n-up-margin' specifies the margin in points between the
522;; sheet border and the n-up printing. The default is 1 cm (or 0.3937 inches,
523;; or 28.35 points).
524;;
525;; If variable `ps-n-up-border-p' is non-nil a border is drawn around each page.
526;; The default is t.
527;;
528;; The variable `ps-n-up-filling' specifies how page matrix is filled on each
529;; sheet of paper. Following are the valid values for `ps-n-up-filling' with a
530;; filling example using a 3x4 page matrix:
531;;
532;; left-top 1 2 3 4 left-bottom 9 10 11 12
533;; 5 6 7 8 5 6 7 8
534;; 9 10 11 12 1 2 3 4
535;;
536;; right-top 4 3 2 1 right-bottom 12 11 10 9
537;; 8 7 6 5 8 7 6 5
538;; 12 11 10 9 4 3 2 1
539;;
540;; top-left 1 4 7 10 bottom-left 3 6 9 12
541;; 2 5 8 11 2 5 8 11
542;; 3 6 9 12 1 4 7 10
543;;
544;; top-right 10 7 4 1 bottom-right 12 9 6 3
545;; 11 8 5 2 11 8 5 2
546;; 12 9 6 3 10 7 4 1
547;;
548;; Any other value is treated as left-top.
549;;
550;; The default value is left-top.
bcc0d457 551;;
06fb6aab 552;;
857686a6
RS
553;; Control And 8-bit Characters
554;; ----------------------------
555;;
556;; The variable `ps-print-control-characters' specifies whether you want to see
557;; a printable form for control and 8-bit characters, that is, instead of
6bdb808e 558;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
857686a6
RS
559;;
560;; Valid values for `ps-print-control-characters' are:
561;;
c82b4a75
KH
562;; 8-bit This is the value to use when you want an ASCII encoding of
563;; any control or non-ASCII character. Control characters are
564;; encoded as "^D", and non-ASCII characters have an
6bdb808e
RS
565;; octal encoding.
566;;
c82b4a75 567;; control-8-bit This is the value to use when you want an ASCII encoding of
6bdb808e
RS
568;; any control character, whether it is 7 or 8-bit.
569;; European 8-bits accented characters are printed according
570;; the current font.
571;;
c82b4a75 572;; control Only ASCII control characters have an ASCII encoding.
6bdb808e
RS
573;; European 8-bits accented characters are printed according
574;; the current font.
575;;
c82b4a75 576;; nil No ASCII encoding. Any character is printed according the
6bdb808e 577;; current font.
857686a6
RS
578;;
579;; Any other value is treated as nil.
580;;
496725ad 581;; The default is `control-8-bit'.
857686a6
RS
582;;
583;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
584;;
585;;
024ced4d
KH
586;; Printing Multi-byte Buffer
587;; --------------------------
d3ab8dac 588;;
298bfad9 589;; See ps-mule.el for documentation.
e65df0a1
KH
590;;
591;;
87a16a06
RS
592;; Line Number
593;; -----------
594;;
a18ed129
RS
595;; The variable `ps-line-number' specifies whether to number each line;
596;; non-nil means do so. The default is nil (don't number each line).
87a16a06 597;;
906d41a7
GM
598;; The variable `ps-line-number-step' specifies the interval that line number is
599;; printed. For example, if `ps-line-number-step' is set to 2, the printing
600;; will look like:
601;;
602;; 1 one line
603;; one line
604;; 3 one line
605;; one line
606;; 4 one line
607;; one line
608;; ...
609;;
610;; Valid values are:
611;;
612;; integer an integer that specifies the interval that line number is
613;; printed. If it's lesser than or equal to zero, it's used the
614;; value 1.
615;;
616;; `zebra' specifies that only the line number of the first line in a zebra
617;; stripe is to be printed.
618;;
619;; Any other value is treated as `zebra'.
620;; The default value is 1, so each line number is printed.
621;;
87a16a06
RS
622;;
623;; Zebra Stripes
624;; -------------
625;;
a18ed129
RS
626;; Zebra stripes are a kind of background that appear "underneath" the text
627;; and can make the text easier to read. They look like this:
87a16a06
RS
628;;
629;; XXXXXXXXXXXXXXXXXXXXXXXX
630;; XXXXXXXXXXXXXXXXXXXXXXXX
535efc38
RS
631;; XXXXXXXXXXXXXXXXXXXXXXXX
632;;
87a16a06
RS
633;;
634;;
635;; XXXXXXXXXXXXXXXXXXXXXXXX
636;; XXXXXXXXXXXXXXXXXXXXXXXX
535efc38 637;; XXXXXXXXXXXXXXXXXXXXXXXX
87a16a06 638;;
06fb6aab 639;; The blocks of X's represent rectangles filled with a light gray color.
a18ed129
RS
640;; Each rectangle extends all the way across the page.
641;;
642;; The height, in lines, of each rectangle is controlled by
535efc38
RS
643;; the variable `ps-zebra-stripe-height', which is 3 by default.
644;; The distance between stripes equals the height of a stripe.
8bd22fcf 645;;
01961237 646;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
a18ed129
RS
647;; Non-nil means yes, nil means no. The default is nil.
648;;
6e1b1da6
GM
649;; The variable `ps-zebra-color' controls the zebra stripes gray scale or RGB
650;; color. It should be a float number between 0.0 (black color) and 1.0 (white
651;; color), a string which is a color name, or a list of 3 numbers which
652;; corresponds to the Red Green Blue color scale.
653;; The default is 0.95 (or "gray95", or '(0.95 0.95 0.95)).
bc0d41bd 654;;
a18ed129 655;; See also section How Ps-Print Has A Text And/Or Image On Background.
87a16a06 656;;
87a16a06 657;;
12b88fff
RS
658;; Hooks
659;; -----
660;;
d3ab8dac 661;; ps-print has the following hook variables:
12b88fff
RS
662;;
663;; `ps-print-hook'
664;; It is evaluated once before any printing process. This is the right
665;; place to initialize ps-print global data.
666;; For an example, see section Adding a New Font Family.
667;;
bc0d41bd
KH
668;; `ps-print-begin-sheet-hook'
669;; It is evaluated on each beginning of sheet of paper.
670;; If `ps-n-up-printing' is equal to 1, `ps-print-begin-page-hook' is never
671;; evaluated.
672;;
12b88fff 673;; `ps-print-begin-page-hook'
bc0d41bd
KH
674;; It is evaluated on each beginning of page, except in the beginning
675;; of page that `ps-print-begin-sheet-hook' is evaluated.
12b88fff
RS
676;;
677;; `ps-print-begin-column-hook'
678;; It is evaluated on each beginning of column, except in the beginning
bc0d41bd
KH
679;; of column that `ps-print-begin-page-hook' is evaluated or that
680;; `ps-print-begin-sheet-hook' is evaluated.
12b88fff
RS
681;;
682;;
683;; Font Managing
bcc0d457
RS
684;; -------------
685;;
7d8b7e8e
KH
686;; ps-print now knows rather precisely some fonts: the variable
687;; `ps-font-info-database' contains information for a list of font families
688;; (currently mainly `Courier' `Helvetica' `Times' `Palatino' `Helvetica-Narrow'
689;; `NewCenturySchlbk'). Each font family contains the font names for standard,
690;; bold, italic and bold-italic characters, a reference size (usually 10) and
691;; the corresponding line height, width of a space and average character width.
06fb6aab 692;;
7d8b7e8e
KH
693;; The variable `ps-font-family' determines which font family is to be used for
694;; ordinary text. If its value does not correspond to a known font family, an
695;; error message is printed into the `*Messages*' buffer, which lists the
696;; currently available font families.
bcc0d457 697;;
7d8b7e8e
KH
698;; The variable `ps-font-size' determines the size (in points) of the font for
699;; ordinary text, when generating PostScript. Its value is a float or a cons of
700;; floats which has the following form:
bcc0d457 701;;
7d8b7e8e
KH
702;; (LANDSCAPE-SIZE . PORTRAIT-SIZE)
703;;
704;; Similarly, the variable `ps-header-font-family' determines which font family
705;; is to be used for text in the header.
706;;
707;; The variable `ps-header-font-size' determines the font size, in points, for
708;; text in the header (similar to `ps-font-size').
709;;
710;; The variable `ps-header-title-font-size' determines the font size, in points,
711;; for the top line of text in the header (similar to `ps-font-size').
bcc0d457
RS
712;;
713;;
12b88fff 714;; Adding a New Font Family
bcc0d457
RS
715;; ------------------------
716;;
717;; To use a new font family, you MUST first teach ps-print
87a16a06 718;; this font, i.e., add its information to `ps-font-info-database',
bcc0d457
RS
719;; otherwise ps-print cannot correctly place line and page breaks.
720;;
87a16a06 721;; For example, assuming `Helvetica' is unknown,
bcc0d457
RS
722;; you first need to do the following ONLY ONCE:
723;;
724;; - create a new buffer
725;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
726;; - open this file and find the line:
727;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
a18ed129 728;; - delete the leading `%' (which is the PostScript comment character)
bcc0d457
RS
729;; - replace in this line `Courier' by the new font (say `Helvetica')
730;; to get the line:
731;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
732;; - send this file to the printer (or to ghostscript).
733;; You should read the following on the output page:
734;;
735;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
736;; and a crude estimate of average character width is 5.09243
737;;
738;; - Add these values to the `ps-font-info-database':
739;; (setq ps-font-info-database
12b88fff
RS
740;; (append
741;; '((Helvetica ; the family key
742;; (fonts (normal . "Helvetica")
743;; (bold . "Helvetica-Bold")
744;; (italic . "Helvetica-Oblique")
745;; (bold-italic . "Helvetica-BoldOblique"))
746;; (size . 10.0)
747;; (line-height . 11.56)
748;; (space-width . 2.78)
749;; (avg-char-width . 5.09243)))
750;; ps-font-info-database))
bcc0d457
RS
751;; - Now you can use this font family with any size:
752;; (setq ps-font-family 'Helvetica)
753;; - if you want to use this family in another emacs session, you must
754;; put into your `~/.emacs':
755;; (require 'ps-print)
756;; (setq ps-font-info-database (append ...)))
757;; if you don't want to load ps-print, you have to copy the whole value:
758;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
12b88fff
RS
759;; or, use `ps-print-hook' (see section Hooks):
760;; (add-hook 'ps-print-hook
bc0d41bd
KH
761;; '(lambda ()
762;; (or (assq 'Helvetica ps-font-info-database)
763;; (setq ps-font-info-database (append ...)))))
bcc0d457
RS
764;;
765;; You can create new `mixed' font families like:
12b88fff
RS
766;; (my-mixed-family
767;; (fonts (normal . "Courier-Bold")
768;; (bold . "Helvetica")
769;; (italic . "Zapf-Chancery-MediumItalic")
770;; (bold-italic . "NewCenturySchlbk-BoldItalic")
771;; (w3-table-hack-x-face . "LineDrawNormal"))
772;; (size . 10.0)
773;; (line-height . 10.55)
774;; (space-width . 6.0)
775;; (avg-char-width . 6.0))
d3ab8dac 776;;
bcc0d457
RS
777;; Now you can use your new font family with any size:
778;; (setq ps-font-family 'my-mixed-family)
779;;
12b88fff
RS
780;; Note that on above example the `w3-table-hack-x-face' entry refers to
781;; a face symbol, so when printing this face it'll be used the font
782;; `LineDrawNormal'. If the face `w3-table-hack-x-face' is remapped to
783;; use bold and/or italic attribute, the corresponding entry (bold, italic
784;; or bold-italic) will be used instead of `w3-table-hack-x-face' entry.
785;;
786;; Note also that the font family entry order is irrelevant, so the above
787;; example could also be written:
788;; (my-mixed-family
789;; (size . 10.0)
790;; (fonts (w3-table-hack-x-face . "LineDrawNormal")
791;; (bold . "Helvetica")
792;; (bold-italic . "NewCenturySchlbk-BoldItalic")
793;; (italic . "Zapf-Chancery-MediumItalic")
794;; (normal . "Courier-Bold"))
795;; (avg-char-width . 6.0)
796;; (space-width . 6.0)
797;; (line-height . 10.55))
798;;
799;; Despite the note above, it is recommended that some convention about
800;; entry order be used.
801;;
bcc0d457
RS
802;; You can get information on all the fonts resident in YOUR printer
803;; by uncommenting the line:
804;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
805;;
a18ed129
RS
806;; The PostScript file should be sent to YOUR PostScript printer.
807;; If you send it to ghostscript or to another PostScript printer,
bcc0d457
RS
808;; you may get slightly different results.
809;; Anyway, as ghostscript fonts are autoload, you won't get
810;; much font info.
811;;
812;;
813;; How Ps-Print Deals With Faces
814;; -----------------------------
12d89a2e 815;;
bcc0d457
RS
816;; The ps-print-*-with-faces commands attempt to determine which faces
817;; should be printed in bold or italic, but their guesses aren't
818;; always right. For example, you might want to map colors into faces
819;; so that blue faces print in bold, and red faces in italic.
12d89a2e 820;;
857686a6
RS
821;; It is possible to force ps-print to consider specific faces bold,
822;; italic or underline, no matter what font they are displayed in, by setting
823;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
824;; These variables contain lists of faces that ps-print should consider bold,
825;; italic or underline; to set them, put code like the following into your
826;; .emacs file:
12d89a2e 827;;
12b88fff 828;; (setq ps-bold-faces '(my-blue-face))
bcc0d457 829;; (setq ps-italic-faces '(my-red-face))
857686a6 830;; (setq ps-underlined-faces '(my-green-face))
bcc0d457
RS
831;;
832;; Faces like bold-italic that are both bold and italic should go in
833;; *both* lists.
834;;
d3ab8dac 835;; ps-print keeps internal lists of which fonts are bold and which are
bcc0d457
RS
836;; italic; these lists are built the first time you invoke ps-print.
837;; For the sake of efficiency, the lists are built only once; the same
838;; lists are referred in later invocations of ps-print.
839;;
840;; Because these lists are built only once, it's possible for them to
841;; get out of sync, if a face changes, or if new faces are added. To
842;; get the lists back in sync, you can set the variable
843;; `ps-build-face-reference' to t, and the lists will be rebuilt the
857686a6
RS
844;; next time ps-print is invoked. If you need that the lists always be
845;; rebuilt when ps-print is invoked, set the variable
846;; `ps-always-build-face-reference' to t.
bcc0d457 847;;
906d41a7
GM
848;; If you need to print without worrying about face background color, set the
849;; variable `ps-use-face-background' which specifies if face background should
850;; be used. Valid values are:
851;;
852;; t always use face background color.
853;; nil never use face background color.
854;; (face...) list of faces whose background color will be used.
855;;
856;; Any other value will be treated as t.
857;; The default value is t.
858;;
bcc0d457
RS
859;;
860;; How Ps-Print Deals With Color
861;; -----------------------------
862;;
d3ab8dac 863;; ps-print detects faces with foreground and background colors
bcc0d457
RS
864;; defined and embeds color information in the PostScript image.
865;; The default foreground and background colors are defined by the
866;; variables `ps-default-fg' and `ps-default-bg'.
6e1b1da6 867;; On black-and-white printers, colors are displayed in gray scale.
bcc0d457
RS
868;; To turn off color output, set `ps-print-color-p' to nil.
869;;
870;;
87a16a06
RS
871;; How Ps-Print Maps Faces
872;; -----------------------
873;;
874;; As ps-print uses PostScript to print buffers, it is possible to have
875;; other attributes associated with faces. So the new attributes used
876;; by ps-print are:
877;;
878;; strikeout - like underline, but the line is in middle of text.
879;; overline - like underline, but the line is over the text.
880;; shadow - text will have a shadow.
881;; box - text will be surrounded by a box.
a18ed129 882;; outline - print characters as hollow outlines.
87a16a06 883;;
06fb6aab 884;; See the documentation for `ps-extend-face'.
87a16a06 885;;
bc0d41bd
KH
886;; Let's, for example, remap `font-lock-keyword-face' to another foreground
887;; color and bold attribute:
87a16a06 888;;
a18ed129 889;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
87a16a06 890;;
6c8f2753
RS
891;; If you want to use a new face, define it first with `defface',
892;; and then call `ps-extend-face' to specify how to print it.
893;;
87a16a06
RS
894;;
895;; How Ps-Print Has A Text And/Or Image On Background
896;; --------------------------------------------------
897;;
d3ab8dac 898;; ps-print can print texts and/or EPS PostScript images on background; it is
87a16a06
RS
899;; possible to define the following text attributes: font name, font size,
900;; initial position, angle, gray scale and pages to print.
901;;
902;; It has the following EPS PostScript images attributes: file name containing
903;; the image, initial position, X and Y scales, angle and pages to print.
904;;
905;; See documentation for `ps-print-background-text' and
906;; `ps-print-background-image'.
907;;
908;; For example, if we wish to print text "preliminary" on all pages and text
909;; "special" on page 5 and from page 11 to page 17, we could specify:
910;;
911;; (setq ps-print-background-text
912;; '(("preliminary")
913;; ("special"
914;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
915;; ; (upper left corner)
916;; nil nil nil
12b88fff 917;; "PrintHeight neg PrintPageWidth atan" ; angle
87a16a06
RS
918;; 5 (11 . 17)) ; page list
919;; ))
920;;
921;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
922;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
923;; specify:
924;;
925;; (setq ps-print-background-image
926;; '(("~/images/EPS-image1.ps"
927;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
928;; ("~/images/EPS-image2.ps"
929;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
930;; ; (upper left corner)
931;; nil nil nil
932;; 5 (11 . 17)) ; page list
933;; ))
934;;
935;; If it is not possible to read (or does not exist) an image file, that file
936;; is ignored.
937;;
938;; The printing order is:
939;;
6e1b1da6
GM
940;; 1. Print background color
941;; 2. Print zebra stripes
942;; 3. Print background texts that it should be on all pages
943;; 4. Print background images that it should be on all pages
944;; 5. Print background texts only for current page (if any)
945;; 6. Print background images only for current page (if any)
946;; 7. Print header
947;; 8. Print buffer text (with faces, if specified) and line number
87a16a06
RS
948;;
949;;
bcc0d457
RS
950;; Utilities
951;; ---------
952;;
953;; Some tools are provided to help you customize your font setup.
954;;
955;; `ps-setup' returns (some part of) the current setup.
956;;
957;; To avoid wrapping too many lines, you may want to adjust the
958;; left and right margins and the font size. On UN*X systems, do:
959;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
960;; to determine the longest lines of your file.
87a16a06 961;; Then, the command `ps-line-lengths' will give you the correspondence
bcc0d457
RS
962;; between a line length (number of characters) and the maximum font
963;; size which doesn't wrap such a line with the current ps-print setup.
964;;
965;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
87a16a06 966;; the correspondence between a number of pages and the maximum font
bcc0d457
RS
967;; size which allow the number of lines of the current buffer or of
968;; its current region to fit in this number of pages.
a18ed129
RS
969;;
970;; NOTE: line folding is not taken into account in this process and could
971;; change the results.
b87c5d3d 972;;
0a5daee5
KH
973;; The command `ps-print-customize' activates a customization buffer for
974;; ps-print options.
975;;
b87c5d3d 976;;
b87c5d3d
RS
977;; New since version 1.5
978;; ---------------------
b87c5d3d 979;;
bcc0d457 980;; Color output capability.
b87c5d3d 981;; Automatic detection of font attributes (bold, italic).
b87c5d3d 982;; Configurable headers with page numbers.
b87c5d3d 983;; Slightly faster.
b87c5d3d 984;; Support for different paper sizes.
b87c5d3d
RS
985;; Better conformance to PostScript Document Structure Conventions.
986;;
ef2cbb24 987;;
bcc0d457
RS
988;; New since version 2.8
989;; ---------------------
990;;
66e63857
GM
991;; [vinicius] 20000310 Vinicius Jose Latorre <vinicius@cpqd.com.br>
992;;
993;; PostScript error handler.
994;; `ps-user-defined-prologue' and `ps-error-handler-message'.
995;;
0a5daee5
KH
996;; [vinicius] 991211 Vinicius Jose Latorre <vinicius@cpqd.com.br>
997;;
998;; `ps-print-customize'.
999;;
bc0d41bd
KH
1000;; [vinicius] 990703 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1001;;
1002;; Better customization.
6e1b1da6 1003;; `ps-banner-page-when-duplexing' and `ps-zebra-color'.
bc0d41bd
KH
1004;;
1005;; [vinicius] 990513 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1006;;
1007;; N-up printing.
1008;; Hook: `ps-print-begin-sheet-hook'.
1009;;
1010;; [keinichi] 990509 Kein'ichi Handa <handa@etl.go.jp>
1011;;
1012;; `ps-print-region-function'
1013;;
1014;; [vinicius] 990301 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1015;;
1016;; PostScript tumble and setpagedevice.
1017;;
d3ab8dac
KH
1018;; [vinicius] 980922 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1019;;
1020;; PostScript prologue header comment insertion.
1021;; Skip invisible text better.
1022;;
e65df0a1
KH
1023;; [keinichi] 980819 Kein'ichi Handa <handa@etl.go.jp>
1024;;
024ced4d 1025;; Multi-byte buffer handling.
e65df0a1 1026;;
12b88fff
RS
1027;; [vinicius] 980306 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1028;;
e65df0a1 1029;; Skip invisible text.
12b88fff
RS
1030;;
1031;; [vinicius] 971130 Vinicius Jose Latorre <vinicius@cpqd.com.br>
1032;;
1033;; Hooks: `ps-print-hook', `ps-print-begin-page-hook' and
1034;; `ps-print-begin-column-hook'.
1035;; Put one header per page over the columns.
1036;; Better database font management.
1037;; Better control characters handling.
1038;;
857686a6 1039;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
87a16a06 1040;;
12b88fff 1041;; Dynamic evaluation at print time of `ps-lpr-switches'.
87a16a06
RS
1042;; Handle control characters.
1043;; Face remapping.
1044;; New face attributes.
1045;; Line number.
1046;; Zebra stripes.
1047;; Text and/or image on background.
1048;;
bcc0d457
RS
1049;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
1050;;
a18ed129 1051;; Font family and float size for text and header.
bcc0d457
RS
1052;; Landscape mode.
1053;; Multiple columns.
1054;; Tools for page setup.
1055;;
1056;;
d3ab8dac 1057;; Known bugs and limitations of ps-print
ef2cbb24 1058;; --------------------------------------
bcc0d457 1059;;
043620f4
KH
1060;; Although color printing will work in XEmacs 19.12, it doesn't work
1061;; well; in particular, bold or italic fonts don't print in the right
1062;; background color.
1063;;
1064;; Invisible properties aren't correctly ignored in XEmacs 19.12.
1065;;
b87c5d3d 1066;; Automatic font-attribute detection doesn't work well, especially
00aa16af 1067;; with hilit19 and older versions of get-create-face. Users having
bcc0d457 1068;; problems with auto-font detection should use the lists
857686a6
RS
1069;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
1070;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
00aa16af 1071;;
043620f4 1072;; Automatic font-attribute detection doesn't work with XEmacs 19.12
857686a6
RS
1073;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
1074;; `ps-underlined-faces' instead.
12d89a2e 1075;;
00aa16af 1076;; Still too slow; could use some hand-optimization.
ef2cbb24 1077;;
12d89a2e 1078;; Default background color isn't working.
ef2cbb24
RS
1079;;
1080;; Faces are always treated as opaque.
1081;;
41481e4b 1082;; Epoch and Emacs 19 not supported. At all.
ef2cbb24 1083;;
06fb6aab 1084;; Fixed-pitch fonts work better for line folding, but are not required.
bcc0d457
RS
1085;;
1086;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
1087;; of folding lines.
ef2cbb24 1088;;
12d89a2e 1089;;
d3ab8dac 1090;; Things to change
bcc0d457 1091;; ----------------
ef2cbb24 1092;;
12b88fff 1093;; Avoid page break inside a paragraph.
bcc0d457 1094;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
bcc0d457
RS
1095;; Improve the memory management for big files (hard?).
1096;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
1097;; of folding lines.
ef2cbb24 1098;;
ef2cbb24 1099;;
12d89a2e
RS
1100;; Acknowledgements
1101;; ----------------
12b88fff 1102;;
906d41a7
GM
1103;; Thanks to David X Callaway <dxc@xprt.net> for helping debugging PostScript
1104;; level 1 compatibility.
1105;;
1106;; Thanks to Colin Marquardt <colin.marquardt@usa.alcatel.com> for upside-down
1107;; and line number step suggestions.
1108;;
66e63857
GM
1109;; Thanks to Klaus Berndl <klaus.berndl@sdm.de> for user defined PostScript
1110;; prologue code suggestion.
1111;;
024ced4d 1112;; Thanks to Kein'ichi Handa <handa@etl.go.jp> for multi-byte buffer handling.
915293a2
KH
1113;;
1114;; Thanks to Matthew O Persico <Matthew.Persico@lazard.com> for line number on
1115;; empty columns.
1116;;
1117;; Thanks to Theodore Jump <tjump@cais.com> for adjust PostScript code order on
1118;; last page.
1119;;
6bdb808e
RS
1120;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
1121;; `ps-print-control-characters' variable documentation.
1122;;
12b88fff
RS
1123;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
1124;; database font management.
1125;;
1126;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
6bdb808e
RS
1127;; header per page over the columns and correct line numbers when printing a
1128;; region.
12b88fff
RS
1129;;
1130;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
1131;; print time of `ps-lpr-switches'.
1132;;
6bdb808e
RS
1133;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
1134;; (his code was severely modified, but the main idea was kept).
1135;;
12b88fff
RS
1136;; Thanks to some suggestions on:
1137;; * Face color map: Marco Melgazzi <marco@techie.com>
1138;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
984e7bd9 1139;; * Check `ps-paper-type': Sudhakar Frederick <sfrederi@asc.corp.mot.com>
12b88fff 1140;;
857686a6
RS
1141;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
1142;; I started from. [vinicius]
1143;;
bcc0d457
RS
1144;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
1145;; [jack]
1146;;
12d89a2e
RS
1147;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
1148;; color and the invisible property.
ef2cbb24 1149;;
12d89a2e
RS
1150;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
1151;; the initial port to Emacs 19. His code is no longer part of
1152;; ps-print, but his work is still appreciated.
ef2cbb24 1153;;
12d89a2e
RS
1154;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
1155;; for adding underline support. Their code also is no longer part of
1156;; ps-print, but their efforts are not forgotten.
1157;;
1158;; Thanks also to all of you who mailed code to add features to
1159;; ps-print; although I didn't use your code, I still appreciate your
1160;; sharing it with me.
1161;;
1162;; Thanks to all who mailed comments, encouragement, and criticism.
1163;; Thanks also to all who responded to my survey; I had too many
1164;; responses to reply to them all, but I greatly appreciate your
1165;; interest.
1166;;
1167;; Jim
bc0d41bd 1168;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ef2cbb24
RS
1169
1170;;; Code:
1171
090be653
RS
1172(unless (featurep 'lisp-float-type)
1173 (error "`ps-print' requires floating point support"))
ef2cbb24 1174
68e684a0 1175
298bfad9 1176;; For Emacs 20.2 and the earlier version.
68e684a0
KH
1177
1178(or (fboundp 'set-buffer-multibyte)
1179 (defun set-buffer-multibyte (arg)
1180 (setq enable-multibyte-characters arg)))
1181
1182(or (fboundp 'string-as-unibyte)
1183 (defun string-as-unibyte (arg) arg))
1184
1185(or (fboundp 'string-as-multibyte)
1186 (defun string-as-multibyte (arg) arg))
1187
1188(or (fboundp 'charset-after)
1189 (defun charset-after (&optional arg)
1190 (char-charset (char-after arg))))
298bfad9 1191
0a5daee5 1192
712dc9e0
GM
1193(or (fboundp 'line-beginning-position)
1194 (defun line-beginning-position (&optional n)
1195 (save-excursion
1196 (and n (/= n 1) (forward-line (1- n)))
1197 (beginning-of-line)
1198 (point))))
1199
1200
906d41a7
GM
1201(defconst ps-windows-system
1202 (memq system-type '(win32 w32 mswindows ms-dos windows-nt)))
1203(defconst ps-lp-system
1204 (memq system-type '(usq-unix-v dgux hpux irix)))
1205
1206
ef2cbb24 1207;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12d89a2e
RS
1208;; User Variables:
1209
0a5daee5 1210
bcc0d457
RS
1211;;; Interface to the command system
1212
bc0d41bd
KH
1213(defgroup postscript nil
1214 "PostScript Group"
1215 :tag "PostScript"
1216 :group 'emacs)
1217
e0af0d3e 1218(defgroup ps-print nil
8bd22fcf 1219 "PostScript generator for Emacs 19"
e0af0d3e 1220 :prefix "ps-"
bc0d41bd
KH
1221 :group 'wp
1222 :group 'postscript)
e0af0d3e
RS
1223
1224(defgroup ps-print-horizontal nil
1225 "Horizontal page layout"
1226 :prefix "ps-"
1227 :tag "Horizontal"
1228 :group 'ps-print)
1229
1230(defgroup ps-print-vertical nil
1231 "Vertical page layout"
1232 :prefix "ps-"
1233 :tag "Vertical"
1234 :group 'ps-print)
1235
6e1b1da6 1236(defgroup ps-print-headers nil
e0af0d3e
RS
1237 "Headers layout"
1238 :prefix "ps-"
1239 :tag "Header"
1240 :group 'ps-print)
1241
1242(defgroup ps-print-font nil
1243 "Fonts customization"
1244 :prefix "ps-"
1245 :tag "Font"
1246 :group 'ps-print)
1247
1248(defgroup ps-print-color nil
1249 "Color customization"
1250 :prefix "ps-"
1251 :tag "Color"
1252 :group 'ps-print)
1253
1254(defgroup ps-print-face nil
1255 "Faces customization"
1256 :prefix "ps-"
1257 :tag "PS Faces"
1258 :group 'ps-print
1259 :group 'faces)
1260
bc0d41bd
KH
1261(defgroup ps-print-n-up nil
1262 "N-up customization"
1263 :prefix "ps-"
1264 :tag "N-Up"
1265 :group 'ps-print)
1266
1267(defgroup ps-print-zebra nil
1268 "Zebra customization"
1269 :prefix "ps-"
1270 :tag "Zebra"
1271 :group 'ps-print)
1272
1273(defgroup ps-print-background nil
1274 "Background customization"
1275 :prefix "ps-"
1276 :tag "Background"
1277 :group 'ps-print)
1278
1279(defgroup ps-print-printer nil
1280 "Printer customization"
1281 :prefix "ps-"
1282 :tag "Printer"
1283 :group 'ps-print)
1284
1285(defgroup ps-print-page nil
1286 "Page customization"
1287 :prefix "ps-"
1288 :tag "Page"
1289 :group 'ps-print)
1290
6e1b1da6
GM
1291(defgroup ps-print-miscellany nil
1292 "Miscellany customization"
1293 :prefix "ps-"
1294 :tag "Miscellany"
1295 :group 'ps-print)
1296
bc0d41bd 1297
66e63857
GM
1298(defcustom ps-error-handler-message 'paper
1299 "*Specify where the error handler message should be sent.
1300
1301Valid values are:
1302
1303 `none' catch the error and *DON'T* send any message.
1304
1305 `paper' catch the error and print on paper the error message.
1306
1307 `system' catch the error and send back the error message to
6e1b1da6
GM
1308 printing system. This is useful only if printing system
1309 send back an email reporting the error, or if there is
1310 some other alternative way to report back the error from
1311 the system to you.
66e63857
GM
1312
1313 `paper-and-system' catch the error, print on paper the error message and
1314 send back the error message to printing system.
1315
1316Any other value is treated as `paper'."
1317 :type '(choice :tag "Error Handler Message"
1318 (const none) (const paper)
1319 (const system) (const paper-and-system))
6e1b1da6 1320 :group 'ps-print-miscellany)
66e63857
GM
1321
1322(defcustom ps-user-defined-prologue nil
1323 "*User defined PostScript prologue code inserted before all prologue code.
1324
1325`ps-user-defined-prologue' may be a string or a symbol function which returns a
1326string. Note that this string is inserted after `ps-adobe-tag' and PostScript
1327prologue comments, and before ps-print PostScript prologue code section. That
1328is, this string is inserted after error handler initialization and before
1329ps-print settings.
1330
1331It's recommended to initiate and terminate the string with \"\\n\".
1332
1333It's strongly recommended only insert PostScript code and/or comments specific
1334for your printing system particularities. For example, some special
1335initialization that only your printing system needs.
1336
1337Do not insert code for duplex printing, n-up printing or error handler, ps-print
1338handles this in a suitable way.
1339
1340For more information about PostScript, see:
1341 PostScript Language Reference Manual (2nd edition)
1342 Adobe Systems Incorporated"
1343 :type '(choice :tag "User Defined Prologue"
edc9cd35 1344 string symbol (const :tag "none" nil))
6e1b1da6 1345 :group 'ps-print-miscellany)
66e63857 1346
d3ab8dac
KH
1347(defcustom ps-print-prologue-header nil
1348 "*PostScript prologue header comments besides that ps-print generates.
1349
1350`ps-print-prologue-header' may be a string or a symbol function which
1351returns a string. Note that this string is inserted on PostScript prologue
1352header section which is used to define some document characteristic through
1353PostScript special comments, like \"%%Requirements: jog\\n\".
1354
1355ps-print always inserts the %%Requirements: comment, so if you need to insert
1356more requirements put them first in `ps-print-prologue-header' using the
1357\"%%+\" comment. For example, if you need to set numcopies to 3 and jog on
1358requirements and set %%LanguageLevel: to 2, do:
1359
1360(setq ps-print-prologue-header
1361 \"%%+ numcopies(3) jog\\n%%LanguageLevel: 2\\n\")
1362
1363The duplex requirement is inserted by ps-print (see `ps-spool-duplex').
1364
1365Do not forget to terminate the string with \"\\n\".
1366
1367For more information about PostScript document comments, see:
1368 PostScript Language Reference Manual (2nd edition)
1369 Adobe Systems Incorporated
1370 Appendix G: Document Structuring Conventions -- Version 3.0"
bc0d41bd 1371 :type '(choice :tag "Prologue Header"
edc9cd35 1372 string symbol (const :tag "none" nil))
6e1b1da6 1373 :group 'ps-print-miscellany)
d3ab8dac 1374
298bfad9
KH
1375(defcustom ps-printer-name (and (boundp 'printer-name)
1376 printer-name)
03820514
RS
1377 "*The name of a local printer for printing PostScript files.
1378
1379On Unix-like systems, a string value should be a name understood by
52cf535f
AI
1380lpr's -P option; a value of nil means use the value of `printer-name'
1381instead. Any other value will be ignored.
1382
1383On MS-DOS and MS-Windows systems, a string value is taken as the name of
1384the printer device or port to which PostScript files are written,
1385provided `ps-lpr-command' is \"\". By default it is the same as
1386`printer-name'; typical non-default settings would be \"LPT1\" to
1387\"LPT3\" for parallel printers, or \"COM1\" to \"COM4\" or \"AUX\" for
1388serial printers, or \"//hostname/printer\" for a shared network printer.
1389You can also set it to a name of a file, in which case the output gets
1390appended to that file. \(Note that `ps-print' package already has
1391facilities for printing to a file, so you might as well use them instead
270a64ac 1392of changing the setting of this variable.\) If you want to silently
52cf535f 1393discard the printed output, set this to \"NUL\"."
bc0d41bd 1394 :type '(choice :tag "Printer Name"
6e1b1da6
GM
1395 (file :tag "Print to file")
1396 (string :tag "Pipe to ps-lpr-command")
edc9cd35 1397 (const :tag "Same as printer-name" nil))
bc0d41bd 1398 :group 'ps-print-printer)
03820514 1399
e0af0d3e 1400(defcustom ps-lpr-command lpr-command
52cf535f
AI
1401 "*Name of program for printing a PostScript file.
1402
1403On MS-DOS and MS-Windows systems, if the value is an empty string then
1404Emacs will write directly to the printer port named by `ps-printer-name'.
1405The programs `print' and `nprint' (the standard print programs on Windows
1406NT and Novell Netware respectively) are handled specially, using
1407`ps-printer-name' as the destination for output; any other program is
1408treated like `lpr' except that an explicit filename is given as the last
1409argument."
e0af0d3e 1410 :type 'string
bc0d41bd 1411 :group 'ps-print-printer)
e0af0d3e
RS
1412
1413(defcustom ps-lpr-switches lpr-switches
1414 "*A list of extra switches to pass to `ps-lpr-command'."
edc9cd35
GM
1415 :type '(repeat :tag "PostScript lpr Switches"
1416 (choice string symbol (repeat sexp)))
bc0d41bd 1417 :group 'ps-print-printer)
12d89a2e 1418
52cf535f 1419(defcustom ps-print-region-function nil
bc0d41bd
KH
1420 "*Specify a function to print the region on a PostScript printer.
1421See definition of `call-process-region' for calling conventions. The fourth and
1422the sixth arguments are both nil."
52cf535f 1423 :type 'function
bc0d41bd 1424 :group 'ps-print-printer)
52cf535f 1425
bcc0d457 1426;;; Page layout
12d89a2e 1427
bcc0d457
RS
1428;; All page dimensions are in PostScript points.
1429;; 1 inch == 2.54 cm == 72 points
1430;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
1431
1432;; Letter 8.5 inch x 11.0 inch
1433;; Legal 8.5 inch x 14.0 inch
1434;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
1435
1436;; LetterSmall 7.68 inch x 10.16 inch
1437;; Tabloid 11.0 inch x 17.0 inch
1438;; Ledger 17.0 inch x 11.0 inch
1439;; Statement 5.5 inch x 8.5 inch
1440;; Executive 7.5 inch x 10.0 inch
1441;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
1442;; A4Small 7.47 inch x 10.85 inch
1443;; B4 10.125 inch x 14.33 inch
1444;; B5 7.16 inch x 10.125 inch
1445
e0af0d3e 1446(defcustom ps-page-dimensions-database
bc0d41bd
KH
1447 (list (list 'a4 (/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54) "A4")
1448 (list 'a3 (/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54) "A3")
1449 (list 'letter (* 72 8.5) (* 72 11.0) "Letter")
1450 (list 'legal (* 72 8.5) (* 72 14.0) "Legal")
1451 (list 'letter-small (* 72 7.68) (* 72 10.16) "LetterSmall")
1452 (list 'tabloid (* 72 11.0) (* 72 17.0) "Tabloid")
1453 (list 'ledger (* 72 17.0) (* 72 11.0) "Ledger")
1454 (list 'statement (* 72 5.5) (* 72 8.5) "Statement")
1455 (list 'executive (* 72 7.5) (* 72 10.0) "Executive")
1456 (list 'a4small (* 72 7.47) (* 72 10.85) "A4Small")
1457 (list 'b4 (* 72 10.125) (* 72 14.33) "B4")
1458 (list 'b5 (* 72 7.16) (* 72 10.125) "B5"))
1459 "*List associating a symbolic paper type to its width, height and doc media.
1460See `ps-paper-type'."
e0af0d3e
RS
1461 :type '(repeat (list :tag "Paper Type"
1462 (symbol :tag "Name")
1463 (number :tag "Width")
bc0d41bd
KH
1464 (number :tag "Height")
1465 (string :tag "Media")))
1466 :group 'ps-print-page)
e0af0d3e 1467
857686a6 1468;;;###autoload
e0af0d3e 1469(defcustom ps-paper-type 'letter
bc0d41bd 1470 "*Specify the size of paper to format for.
090be653 1471Should be one of the paper types defined in `ps-page-dimensions-database', for
e0af0d3e
RS
1472example `letter', `legal' or `a4'."
1473 :type '(symbol :validate (lambda (wid)
87a16a06
RS
1474 (if (assq (widget-value wid)
1475 ps-page-dimensions-database)
e0af0d3e
RS
1476 nil
1477 (widget-put wid :error "Unknown paper size")
1478 wid)))
bc0d41bd 1479 :group 'ps-print-page)
e0af0d3e 1480
87a16a06 1481(defcustom ps-landscape-mode nil
e0af0d3e
RS
1482 "*Non-nil means print in landscape mode."
1483 :type 'boolean
bc0d41bd 1484 :group 'ps-print-page)
e0af0d3e 1485
906d41a7
GM
1486(defcustom ps-print-upside-down nil
1487 "*Non-nil means print upside-down."
1488 :type 'boolean
1489 :group 'ps-print-page)
1490
857686a6 1491(defcustom ps-print-control-characters 'control-8-bit
bc0d41bd
KH
1492 "*Specify the printable form for control and 8-bit characters.
1493That is, instead of sending, for example, a ^D (\\004) to printer,
915293a2 1494it is sent the string \"^D\".
6bdb808e 1495
857686a6 1496Valid values are:
6bdb808e 1497
984e7bd9 1498 `8-bit' This is the value to use when you want an ASCII encoding of
d3ab8dac
KH
1499 any control or non-ASCII character. Control characters are
1500 encoded as \"^D\", and non-ASCII characters have an
1501 octal encoding.
6bdb808e 1502
984e7bd9 1503 `control-8-bit' This is the value to use when you want an ASCII encoding of
d3ab8dac
KH
1504 any control character, whether it is 7 or 8-bit.
1505 European 8-bits accented characters are printed according
1506 the current font.
6bdb808e 1507
c82b4a75 1508 `control' Only ASCII control characters have an ASCII encoding.
d3ab8dac
KH
1509 European 8-bits accented characters are printed according
1510 the current font.
6bdb808e 1511
984e7bd9 1512 nil No ASCII encoding. Any character is printed according the
d3ab8dac 1513 current font.
6bdb808e 1514
857686a6 1515Any other value is treated as nil."
bc0d41bd
KH
1516 :type '(choice :tag "Control Char"
1517 (const 8-bit) (const control-8-bit)
edc9cd35 1518 (const control) (const :tag "nil" nil))
6e1b1da6 1519 :group 'ps-print-miscellany)
857686a6 1520
bc0d41bd
KH
1521(defcustom ps-n-up-printing 1
1522 "*Specify the number of pages per sheet paper."
1523 :type '(integer
1524 :tag "N Up Printing"
1525 :validate
1526 (lambda (wid)
1527 (if (and (< 0 (widget-value wid))
1528 (<= (widget-value wid) 100))
1529 nil
1530 (widget-put
1531 wid :error
1532 "Number of pages per sheet paper must be between 1 and 100.")
1533 wid)))
1534 :group 'ps-print-n-up)
1535
1536(defcustom ps-n-up-margin (/ (* 72 1.0) 2.54) ; 1 cm
1537 "*Specify the margin in points between the sheet border and n-up printing."
1538 :type 'number
1539 :group 'ps-print-n-up)
1540
1541(defcustom ps-n-up-border-p t
1542 "*Non-nil means a border is drawn around each page."
1543 :type 'boolean
1544 :group 'ps-print-n-up)
1545
1546(defcustom ps-n-up-filling 'left-top
1547 "*Specify how page matrix is filled on each sheet of paper.
1548
1549Following are the valid values for `ps-n-up-filling' with a filling example
1550using a 3x4 page matrix:
1551
1552 `left-top' 1 2 3 4 `left-bottom' 9 10 11 12
1553 5 6 7 8 5 6 7 8
1554 9 10 11 12 1 2 3 4
1555
1556 `right-top' 4 3 2 1 `right-bottom' 12 11 10 9
1557 8 7 6 5 8 7 6 5
1558 12 11 10 9 4 3 2 1
1559
1560 `top-left' 1 4 7 10 `bottom-left' 3 6 9 12
1561 2 5 8 11 2 5 8 11
1562 3 6 9 12 1 4 7 10
1563
1564 `top-right' 10 7 4 1 `bottom-right' 12 9 6 3
1565 11 8 5 2 11 8 5 2
1566 12 9 6 3 10 7 4 1
1567
1568Any other value is treated as `left-top'."
1569 :type '(choice :tag "N-Up Filling"
1570 (const left-top) (const left-bottom)
1571 (const right-top) (const right-bottom)
1572 (const top-left) (const bottom-left)
1573 (const top-right) (const bottom-right))
1574 :group 'ps-print-n-up)
1575
e0af0d3e 1576(defcustom ps-number-of-columns (if ps-landscape-mode 2 1)
bc0d41bd 1577 "*Specify the number of columns"
87a16a06 1578 :type 'number
6e1b1da6 1579 :group 'ps-print-miscellany)
87a16a06 1580
535efc38 1581(defcustom ps-zebra-stripes nil
87a16a06 1582 "*Non-nil means print zebra stripes.
6e1b1da6 1583See also documentation for `ps-zebra-stripe-height' and `ps-zebra-color'."
87a16a06 1584 :type 'boolean
bc0d41bd 1585 :group 'ps-print-zebra)
87a16a06 1586
535efc38 1587(defcustom ps-zebra-stripe-height 3
87a16a06 1588 "*Number of zebra stripe lines.
6e1b1da6 1589See also documentation for `ps-zebra-stripes' and `ps-zebra-color'."
87a16a06 1590 :type 'number
bc0d41bd
KH
1591 :group 'ps-print-zebra)
1592
6e1b1da6
GM
1593(defcustom ps-zebra-color 0.95
1594 "*Zebra stripe gray scale or RGB color.
bc0d41bd 1595See also documentation for `ps-zebra-stripes' and `ps-zebra-stripe-height'."
6e1b1da6
GM
1596 :type '(choice :tag "Zebra Gray/Color"
1597 (number :tag "Gray Scale" :value 0.95)
1598 (string :tag "Color Name" :value "gray95")
1599 (list :tag "RGB Color" :value (0.95 0.95 0.95)
1600 (number :tag "Red")
1601 (number :tag "Green")
1602 (number :tag "Blue")))
bc0d41bd 1603 :group 'ps-print-zebra)
87a16a06
RS
1604
1605(defcustom ps-line-number nil
1606 "*Non-nil means print line number."
1607 :type 'boolean
6e1b1da6 1608 :group 'ps-print-miscellany)
87a16a06 1609
906d41a7
GM
1610(defcustom ps-line-number-step 1
1611 "*Specify the interval that line number is printed.
1612
1613For example, `ps-line-number-step' is set to 2, the printing will look like:
1614
1615 1 one line
1616 one line
1617 3 one line
1618 one line
1619 4 one line
1620 one line
1621 ...
1622
1623Valid values are:
1624
1625 integer an integer that specifies the interval that line number is
1626 printed. If it's lesser than or equal to zero, it's used the
1627 value 1.
1628
1629 `zebra' specifies that only the line number of the first line in a zebra
1630 stripe is to be printed.
1631
1632Any other value is treated as `zebra'."
1633 :type '(choice :tag "Line Number Step"
1634 (integer :tag "Step Interval")
1635 (const :tag "Synchronize Zebra" zebra))
1636 :group 'ps-print-miscellany)
1637
87a16a06
RS
1638(defcustom ps-print-background-image nil
1639 "*EPS image list to be printed on background.
1640
1641The elements are:
1642
1643 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
1644
1645FILENAME is a file name which contains an EPS image or some PostScript
1646programming like EPS.
1647FILENAME is ignored, if it doesn't exist or is read protected.
1648
1649X and Y are relative positions on paper to put the image.
1650If X and Y are nil, the image is centralized on paper.
1651
1652XSCALE and YSCALE are scale factor to be applied to image before printing.
1653If XSCALE and YSCALE are nil, the original size is used.
1654
1655ROTATION is the image rotation angle; if nil, the default is 0.
1656
1657PAGES designates the page to print background image.
1658PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1659to TO page.
1660If PAGES is nil, print background image on all pages.
1661
1662X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
1663an integer number or a string. If it is a string, the string should contain
1664PostScript programming that returns a float or integer value.
1665
1666For example, if you wish to print an EPS image on all pages do:
1667
1668 '((\"~/images/EPS-image.ps\"))"
bc0d41bd 1669 :type '(repeat (list (file :tag "EPS File")
6e1b1da6
GM
1670 (choice :tag "X" (const :tag "default" nil) number string)
1671 (choice :tag "Y" (const :tag "default" nil) number string)
1672 (choice :tag "X Scale" (const :tag "default" nil) number string)
1673 (choice :tag "Y Scale" (const :tag "default" nil) number string)
1674 (choice :tag "Rotation" (const :tag "default" nil) number string)
35378a09 1675 (repeat :tag "Pages" :inline t
bc0d41bd 1676 (radio (integer :tag "Page")
35378a09
KH
1677 (cons :tag "Range"
1678 (integer :tag "From")
1679 (integer :tag "To"))))))
bc0d41bd 1680 :group 'ps-print-background)
87a16a06
RS
1681
1682(defcustom ps-print-background-text nil
1683 "*Text list to be printed on background.
1684
1685The elements are:
1686
1687 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
1688
1689STRING is the text to be printed on background.
1690
1691X and Y are positions on paper to put the text.
1692If X and Y are nil, the text is positioned at lower left corner.
1693
1694FONT is a font name to be used on printing the text.
1695If nil, \"Times-Roman\" is used.
1696
1697FONTSIZE is font size to be used, if nil, 200 is used.
1698
1699GRAY is the text gray factor (should be very light like 0.8).
1700If nil, the default is 0.85.
1701
1702ROTATION is the text rotation angle; if nil, the angle is given by
1703the diagonal from lower left corner to upper right corner.
1704
1705PAGES designates the page to print background text.
1706PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1707to TO page.
1708If PAGES is nil, print background text on all pages.
1709
1710X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1711an integer number or a string. If it is a string, the string should contain
1712PostScript programming that returns a float or integer value.
1713
1714For example, if you wish to print text \"Preliminary\" on all pages do:
1715
1716 '((\"Preliminary\"))"
bc0d41bd 1717 :type '(repeat (list (string :tag "Text")
6e1b1da6
GM
1718 (choice :tag "X" (const :tag "default" nil) number string)
1719 (choice :tag "Y" (const :tag "default" nil) number string)
1720 (choice :tag "Font" (const :tag "default" nil) string)
1721 (choice :tag "Fontsize" (const :tag "default" nil) number string)
1722 (choice :tag "Gray" (const :tag "default" nil) number string)
1723 (choice :tag "Rotation" (const :tag "default" nil) number string)
35378a09 1724 (repeat :tag "Pages" :inline t
bc0d41bd 1725 (radio (integer :tag "Page")
35378a09
KH
1726 (cons :tag "Range"
1727 (integer :tag "From")
1728 (integer :tag "To"))))))
bc0d41bd 1729 :group 'ps-print-background)
bcc0d457
RS
1730
1731;;; Horizontal layout
1732
1733;; ------------------------------------------
1734;; | | | | | | | |
1735;; | lm | text | ic | text | ic | text | rm |
1736;; | | | | | | | |
1737;; ------------------------------------------
1738
e0af0d3e
RS
1739(defcustom ps-left-margin (/ (* 72 2.0) 2.54) ; 2 cm
1740 "*Left margin in points (1/72 inch)."
1741 :type 'number
1742 :group 'ps-print-horizontal)
bcc0d457 1743
e0af0d3e
RS
1744(defcustom ps-right-margin (/ (* 72 2.0) 2.54) ; 2 cm
1745 "*Right margin in points (1/72 inch)."
1746 :type 'number
1747 :group 'ps-print-horizontal)
bcc0d457 1748
e0af0d3e
RS
1749(defcustom ps-inter-column (/ (* 72 2.0) 2.54) ; 2 cm
1750 "*Horizontal space between columns in points (1/72 inch)."
1751 :type 'number
1752 :group 'ps-print-horizontal)
bcc0d457
RS
1753
1754;;; Vertical layout
1755
1756;; |--------|
1757;; | tm |
1758;; |--------|
1759;; | header |
1760;; |--------|
1761;; | ho |
1762;; |--------|
1763;; | text |
1764;; |--------|
1765;; | bm |
1766;; |--------|
1767
e0af0d3e
RS
1768(defcustom ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
1769 "*Bottom margin in points (1/72 inch)."
1770 :type 'number
1771 :group 'ps-print-vertical)
bcc0d457 1772
e0af0d3e
RS
1773(defcustom ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
1774 "*Top margin in points (1/72 inch)."
1775 :type 'number
1776 :group 'ps-print-vertical)
bcc0d457 1777
e0af0d3e
RS
1778(defcustom ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
1779 "*Vertical space in points (1/72 inch) between the main text and the header."
1780 :type 'number
1781 :group 'ps-print-vertical)
bcc0d457 1782
e0af0d3e 1783(defcustom ps-header-line-pad 0.15
bcc0d457 1784 "*Portion of a header title line height to insert between the header frame
e0af0d3e
RS
1785and the text it contains, both in the vertical and horizontal directions."
1786 :type 'number
1787 :group 'ps-print-vertical)
bcc0d457
RS
1788
1789;;; Header setup
12d89a2e 1790
e0af0d3e 1791(defcustom ps-print-header t
86c10ecb
RS
1792 "*Non-nil means print a header at the top of each page.
1793By default, the header displays the buffer name, page number, and, if
1794the buffer is visiting a file, the file's directory. Headers are
ae7f6761 1795customizable by changing variables `ps-left-header' and
e0af0d3e
RS
1796`ps-right-header'."
1797 :type 'boolean
6e1b1da6 1798 :group 'ps-print-headers)
e0af0d3e 1799
12b88fff
RS
1800(defcustom ps-print-only-one-header nil
1801 "*Non-nil means print only one header at the top of each page.
1802This is useful when printing more than one column, so it is possible
1803to have only one header over all columns or one header per column.
1804See also `ps-print-header'."
1805 :type 'boolean
6e1b1da6 1806 :group 'ps-print-headers)
12b88fff 1807
e0af0d3e
RS
1808(defcustom ps-print-header-frame t
1809 "*Non-nil means draw a gaudy frame around the header."
1810 :type 'boolean
6e1b1da6 1811 :group 'ps-print-headers)
e0af0d3e
RS
1812
1813(defcustom ps-header-lines 2
8bd22fcf 1814 "*Number of lines to display in page header, when generating PostScript."
e0af0d3e 1815 :type 'integer
6e1b1da6 1816 :group 'ps-print-headers)
bcc0d457 1817
e0af0d3e 1818(defcustom ps-show-n-of-n t
00aa16af 1819 "*Non-nil means show page numbers as N/M, meaning page N of M.
8bd22fcf 1820NOTE: page numbers are displayed as part of headers,
6e1b1da6 1821 see variable `ps-print-header'."
e0af0d3e 1822 :type 'boolean
6e1b1da6 1823 :group 'ps-print-headers)
12d89a2e 1824
edc9cd35 1825(defcustom ps-spool-config
906d41a7 1826 (if ps-windows-system
edc9cd35
GM
1827 nil
1828 'lpr-switches)
bc0d41bd
KH
1829 "*Specify who is responsable for setting duplex and page size switches.
1830
1831Valid values are:
1832
1833 `lpr-switches' duplex and page size are configured by `ps-lpr-switches'.
1834 Don't forget to set `ps-lpr-switches' to select duplex
1835 printing for your printer.
1836
1837 `setpagedevice' duplex and page size are configured by ps-print using the
1838 setpagedevice PostScript operator.
1839
1840 nil duplex and page size are configured by ps-print *not* using
1841 the setpagedevice PostScript operator.
1842
1843Any other value is treated as nil.
1844
1845WARNING: The setpagedevice PostScript operator affects ghostview utility when
1846 viewing file generated using landscape. Also on some printers,
1847 setpagedevice affects zebra stripes; on other printers, setpagedevice
1848 affects the left margin.
1849 Besides all that, if your printer does not have the paper size
1850 specified by setpagedevice, your printing will be aborted.
1851 So, if you need to use setpagedevice, set `ps-spool-config' to
1852 `setpagedevice', generate a test file and send it to your printer; if
1853 the printed file isn't ok, set `ps-spool-config' to nil."
1854 :type '(choice :tag "Spool Config"
1855 (const lpr-switches) (const setpagedevice)
edc9cd35 1856 (const :tag "nil" nil))
6e1b1da6 1857 :group 'ps-print-headers)
bc0d41bd
KH
1858
1859(defcustom ps-spool-duplex nil ; Not many people have duplex printers,
1860 ; so default to nil.
1861 "*Non-nil generates PostScript for a two-sided printer.
1862For a duplex printer, the `ps-spool-*' and `ps-print-*' commands will insert
1863blank pages as needed between print jobs so that the next buffer printed will
1864start on the right page. Also, if headers are turned on, the headers will be
1865reversed on duplex printers so that the page numbers fall to the left on
0a5daee5
KH
1866even-numbered pages.
1867
1868See also `ps-spool-tumble'."
bc0d41bd 1869 :type 'boolean
6e1b1da6 1870 :group 'ps-print-headers)
bc0d41bd
KH
1871
1872(defcustom ps-spool-tumble nil
1873 "*Specify how the page images on opposite sides of a sheet are oriented.
1874If `ps-spool-tumble' is nil, produces output suitable for binding on the left or
1875right. If `ps-spool-tumble' is non-nil, produces output suitable for binding at
1876the top or bottom.
1877
1878It has effect only when `ps-spool-duplex' is non-nil."
e0af0d3e 1879 :type 'boolean
6e1b1da6 1880 :group 'ps-print-headers)
bcc0d457
RS
1881
1882;;; Fonts
1883
e0af0d3e 1884(defcustom ps-font-info-database
bcc0d457 1885 '((Courier ; the family key
12b88fff
RS
1886 (fonts (normal . "Courier")
1887 (bold . "Courier-Bold")
1888 (italic . "Courier-Oblique")
1889 (bold-italic . "Courier-BoldOblique"))
1890 (size . 10.0)
1891 (line-height . 10.55)
1892 (space-width . 6.0)
1893 (avg-char-width . 6.0))
bcc0d457 1894 (Helvetica ; the family key
12b88fff
RS
1895 (fonts (normal . "Helvetica")
1896 (bold . "Helvetica-Bold")
1897 (italic . "Helvetica-Oblique")
1898 (bold-italic . "Helvetica-BoldOblique"))
1899 (size . 10.0)
1900 (line-height . 11.56)
1901 (space-width . 2.78)
1902 (avg-char-width . 5.09243))
bcc0d457 1903 (Times
12b88fff
RS
1904 (fonts (normal . "Times-Roman")
1905 (bold . "Times-Bold")
1906 (italic . "Times-Italic")
1907 (bold-italic . "Times-BoldItalic"))
1908 (size . 10.0)
1909 (line-height . 11.0)
1910 (space-width . 2.5)
334cc3b7 1911 (avg-char-width . 4.71432))
bcc0d457 1912 (Palatino
12b88fff
RS
1913 (fonts (normal . "Palatino-Roman")
1914 (bold . "Palatino-Bold")
1915 (italic . "Palatino-Italic")
1916 (bold-italic . "Palatino-BoldItalic"))
1917 (size . 10.0)
1918 (line-height . 12.1)
1919 (space-width . 2.5)
1920 (avg-char-width . 5.08676))
bcc0d457 1921 (Helvetica-Narrow
12b88fff
RS
1922 (fonts (normal . "Helvetica-Narrow")
1923 (bold . "Helvetica-Narrow-Bold")
1924 (italic . "Helvetica-Narrow-Oblique")
1925 (bold-italic . "Helvetica-Narrow-BoldOblique"))
1926 (size . 10.0)
1927 (line-height . 11.56)
1928 (space-width . 2.2796)
1929 (avg-char-width . 4.17579))
bcc0d457 1930 (NewCenturySchlbk
12b88fff
RS
1931 (fonts (normal . "NewCenturySchlbk-Roman")
1932 (bold . "NewCenturySchlbk-Bold")
1933 (italic . "NewCenturySchlbk-Italic")
1934 (bold-italic . "NewCenturySchlbk-BoldItalic"))
1935 (size . 10.0)
334cc3b7 1936 (line-height . 12.15)
12b88fff
RS
1937 (space-width . 2.78)
1938 (avg-char-width . 5.31162))
bcc0d457
RS
1939 ;; got no bold for the next ones
1940 (AvantGarde-Book
12b88fff
RS
1941 (fonts (normal . "AvantGarde-Book")
1942 (italic . "AvantGarde-BookOblique"))
1943 (size . 10.0)
1944 (line-height . 11.77)
1945 (space-width . 2.77)
1946 (avg-char-width . 5.45189))
bcc0d457 1947 (AvantGarde-Demi
12b88fff
RS
1948 (fonts (normal . "AvantGarde-Demi")
1949 (italic . "AvantGarde-DemiOblique"))
1950 (size . 10.0)
1951 (line-height . 12.72)
1952 (space-width . 2.8)
1953 (avg-char-width . 5.51351))
bcc0d457 1954 (Bookman-Demi
12b88fff
RS
1955 (fonts (normal . "Bookman-Demi")
1956 (italic . "Bookman-DemiItalic"))
1957 (size . 10.0)
1958 (line-height . 11.77)
1959 (space-width . 3.4)
1960 (avg-char-width . 6.05946))
bcc0d457 1961 (Bookman-Light
12b88fff
RS
1962 (fonts (normal . "Bookman-Light")
1963 (italic . "Bookman-LightItalic"))
1964 (size . 10.0)
1965 (line-height . 11.79)
1966 (space-width . 3.2)
1967 (avg-char-width . 5.67027))
bcc0d457
RS
1968 ;; got no bold and no italic for the next ones
1969 (Symbol
12b88fff
RS
1970 (fonts (normal . "Symbol"))
1971 (size . 10.0)
1972 (line-height . 13.03)
1973 (space-width . 2.5)
1974 (avg-char-width . 3.24324))
bcc0d457 1975 (Zapf-Dingbats
12b88fff
RS
1976 (fonts (normal . "Zapf-Dingbats"))
1977 (size . 10.0)
1978 (line-height . 9.63)
1979 (space-width . 2.78)
1980 (avg-char-width . 2.78))
bcc0d457 1981 (Zapf-Chancery-MediumItalic
12b88fff
RS
1982 (fonts (normal . "Zapf-Chancery-MediumItalic"))
1983 (size . 10.0)
1984 (line-height . 11.45)
1985 (space-width . 2.2)
1986 (avg-char-width . 4.10811))
87a16a06 1987 )
bcc0d457
RS
1988 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1989reference size, line height, space width, average character width.
1990To get the info for another specific font (say Helvetica), do the following:
1991- create a new buffer
1992- generate the PostScript image to a file (C-u M-x ps-print-buffer)
8bd22fcf 1993- open this file and delete the leading `%' (which is the PostScript
bcc0d457 1994 comment character) from the line
87a16a06 1995 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
bcc0d457 1996 to get the line
87a16a06 1997 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
bcc0d457 1998- add the values to `ps-font-info-database'.
e0af0d3e
RS
1999You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
2000 :type '(repeat (list :tag "Font Definition"
12b88fff 2001 (symbol :tag "Font Family")
334cc3b7
AS
2002 (cons :format "%v"
2003 (const :format "" fonts)
2004 (repeat :tag "Faces"
2005 (cons (choice (const normal)
12b88fff
RS
2006 (const bold)
2007 (const italic)
2008 (const bold-italic)
2009 (symbol :tag "Face"))
2010 (string :tag "Font Name"))))
334cc3b7
AS
2011 (cons :format "%v"
2012 (const :format "" size)
12b88fff 2013 (number :tag "Reference Size"))
334cc3b7
AS
2014 (cons :format "%v"
2015 (const :format "" line-height)
12b88fff 2016 (number :tag "Line Height"))
334cc3b7
AS
2017 (cons :format "%v"
2018 (const :format "" space-width)
12b88fff 2019 (number :tag "Space Width"))
334cc3b7
AS
2020 (cons :format "%v"
2021 (const :format "" avg-char-width)
12b88fff 2022 (number :tag "Average Character Width"))))
e0af0d3e
RS
2023 :group 'ps-print-font)
2024
2025(defcustom ps-font-family 'Courier
d3ab8dac 2026 "*Font family name for ordinary text, when generating PostScript."
e0af0d3e
RS
2027 :type 'symbol
2028 :group 'ps-print-font)
2029
7d8b7e8e 2030(defcustom ps-font-size '(7 . 8.5)
d3ab8dac 2031 "*Font size, in points, for ordinary text, when generating PostScript."
7d8b7e8e
KH
2032 :type '(choice (number :tag "Text Size")
2033 (cons :tag "Landscape/Portrait"
2034 (number :tag "Landscape Text Size")
2035 (number :tag "Portrait Text Size")))
e0af0d3e
RS
2036 :group 'ps-print-font)
2037
2038(defcustom ps-header-font-family 'Helvetica
d3ab8dac 2039 "*Font family name for text in the header, when generating PostScript."
e0af0d3e
RS
2040 :type 'symbol
2041 :group 'ps-print-font)
2042
7d8b7e8e 2043(defcustom ps-header-font-size '(10 . 12)
d3ab8dac 2044 "*Font size, in points, for text in the header, when generating PostScript."
7d8b7e8e
KH
2045 :type '(choice (number :tag "Header Size")
2046 (cons :tag "Landscape/Portrait"
2047 (number :tag "Landscape Header Size")
2048 (number :tag "Portrait Header Size")))
e0af0d3e
RS
2049 :group 'ps-print-font)
2050
7d8b7e8e 2051(defcustom ps-header-title-font-size '(12 . 14)
d3ab8dac 2052 "*Font size, in points, for the top line of text in header, in PostScript."
7d8b7e8e
KH
2053 :type '(choice (number :tag "Header Title Size")
2054 (cons :tag "Landscape/Portrait"
2055 (number :tag "Landscape Header Title Size")
2056 (number :tag "Portrait Header Title Size")))
e0af0d3e 2057 :group 'ps-print-font)
bcc0d457
RS
2058
2059;;; Colors
2060
87a16a06
RS
2061;; Printing color requires x-color-values.
2062(defcustom ps-print-color-p (or (fboundp 'x-color-values) ; Emacs
857686a6
RS
2063 (fboundp 'color-instance-rgb-components))
2064 ; XEmacs
bc0d41bd 2065 "*Non-nil means print the buffer's text in color."
e0af0d3e
RS
2066 :type 'boolean
2067 :group 'ps-print-color)
12d89a2e 2068
e0af0d3e
RS
2069(defcustom ps-default-fg '(0.0 0.0 0.0)
2070 "*RGB values of the default foreground color. Defaults to black."
6e1b1da6
GM
2071 :type '(choice :tag "Default Foreground Gray/Color"
2072 (number :tag "Gray Scale" :value 0.0)
2073 (string :tag "Color Name" :value "black")
2074 (list :tag "RGB Color" :value (0.0 0.0 0.0)
2075 (number :tag "Red")
2076 (number :tag "Green")
2077 (number :tag "Blue")))
e0af0d3e 2078 :group 'ps-print-color)
12d89a2e 2079
e0af0d3e
RS
2080(defcustom ps-default-bg '(1.0 1.0 1.0)
2081 "*RGB values of the default background color. Defaults to white."
6e1b1da6
GM
2082 :type '(choice :tag "Default Background Gray/Color"
2083 (number :tag "Gray Scale" :value 1.0)
2084 (string :tag "Color Name" :value "white")
2085 (list :tag "RGB Color" :value (1.0 1.0 1.0)
2086 (number :tag "Red")
2087 (number :tag "Green")
2088 (number :tag "Blue")))
e0af0d3e 2089 :group 'ps-print-color)
12d89a2e 2090
e0af0d3e 2091(defcustom ps-auto-font-detect t
12d89a2e 2092 "*Non-nil means automatically detect bold/italic face attributes.
7f72c06f 2093If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
e0af0d3e
RS
2094and `ps-underlined-faces'."
2095 :type 'boolean
2096 :group 'ps-print-font)
12d89a2e 2097
e0af0d3e 2098(defcustom ps-bold-faces
090be653
RS
2099 (unless ps-print-color-p
2100 '(font-lock-function-name-face
2101 font-lock-builtin-face
2102 font-lock-variable-name-face
2103 font-lock-keyword-face
2104 font-lock-warning-face))
86c10ecb 2105 "*A list of the \(non-bold\) faces that should be printed in bold font.
8bd22fcf 2106This applies to generating PostScript."
e0af0d3e
RS
2107 :type '(repeat face)
2108 :group 'ps-print-face)
12d89a2e 2109
e0af0d3e 2110(defcustom ps-italic-faces
090be653
RS
2111 (unless ps-print-color-p
2112 '(font-lock-variable-name-face
8bd22fcf 2113 font-lock-type-face
090be653
RS
2114 font-lock-string-face
2115 font-lock-comment-face
2116 font-lock-warning-face))
86c10ecb 2117 "*A list of the \(non-italic\) faces that should be printed in italic font.
8bd22fcf 2118This applies to generating PostScript."
e0af0d3e
RS
2119 :type '(repeat face)
2120 :group 'ps-print-face)
12d89a2e 2121
e0af0d3e 2122(defcustom ps-underlined-faces
090be653
RS
2123 (unless ps-print-color-p
2124 '(font-lock-function-name-face
883212ce 2125 font-lock-constant-face
090be653 2126 font-lock-warning-face))
86c10ecb 2127 "*A list of the \(non-underlined\) faces that should be printed underlined.
8bd22fcf 2128This applies to generating PostScript."
e0af0d3e
RS
2129 :type '(repeat face)
2130 :group 'ps-print-face)
12d89a2e 2131
906d41a7
GM
2132(defcustom ps-use-face-background nil
2133 "*Specify if face background should be used.
2134
2135Valid values are:
2136
2137 t always use face background color.
2138 nil never use face background color.
2139 (face...) list of faces whose background color will be used.
2140
2141Any other value will be treated as t."
2142 :type '(choice :tag "Use Face Background"
2143 (const :tag "Always Use Face Background" t)
2144 (const :tag "Never Use Face Background" nil)
2145 (repeat :menu-tag "Face Background List"
2146 :tag "Face Background List"
2147 face))
2148 :group 'ps-print-face)
2149
e0af0d3e 2150(defcustom ps-left-header
12d89a2e 2151 (list 'ps-get-buffer-name 'ps-header-dirpart)
bcc0d457 2152 "*The items to display (each on a line) on the left part of the page header.
8bd22fcf 2153This applies to generating PostScript.
12d89a2e 2154
86c10ecb 2155The value should be a list of strings and symbols, each representing an
12d89a2e
RS
2156entry in the PostScript array HeaderLinesLeft.
2157
2158Strings are inserted unchanged into the array; those representing
2159PostScript string literals should be delimited with PostScript string
2160delimiters '(' and ')'.
2161
2162For symbols with bound functions, the function is called and should
2163return a string to be inserted into the array. For symbols with bound
2164values, the value should be a string to be inserted into the array.
2165In either case, function or variable, the string value has PostScript
e0af0d3e
RS
2166string delimiters added to it."
2167 :type '(repeat (choice string symbol))
6e1b1da6 2168 :group 'ps-print-headers)
12d89a2e 2169
e0af0d3e 2170(defcustom ps-right-header
090be653 2171 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss)
bcc0d457 2172 "*The items to display (each on a line) on the right part of the page header.
8bd22fcf 2173This applies to generating PostScript.
12d89a2e 2174
86c10ecb 2175See the variable `ps-left-header' for a description of the format of
e0af0d3e
RS
2176this variable."
2177 :type '(repeat (choice string symbol))
6e1b1da6 2178 :group 'ps-print-headers)
ef2cbb24 2179
e0af0d3e
RS
2180(defcustom ps-razzle-dazzle t
2181 "*Non-nil means report progress while formatting buffer."
2182 :type 'boolean
6e1b1da6 2183 :group 'ps-print-miscellany)
12d89a2e 2184
a18ed129 2185(defcustom ps-adobe-tag "%!PS-Adobe-3.0\n"
12d89a2e
RS
2186 "*Contains the header line identifying the output as PostScript.
2187By default, `ps-adobe-tag' contains the standard identifier. Some
a18ed129
RS
2188printers require slightly different versions of this line."
2189 :type 'string
6e1b1da6 2190 :group 'ps-print-miscellany)
12d89a2e 2191
e0af0d3e 2192(defcustom ps-build-face-reference t
12d89a2e
RS
2193 "*Non-nil means build the reference face lists.
2194
d3ab8dac 2195ps-print sets this value to nil after it builds its internal reference
12d89a2e
RS
2196lists of bold and italic faces. By settings its value back to t, you
2197can force ps-print to rebuild the lists the next time you invoke one
86c10ecb 2198of the ...-with-faces commands.
12d89a2e
RS
2199
2200You should set this value back to t after you change the attributes of
2201any face, or create new faces. Most users shouldn't have to worry
e0af0d3e
RS
2202about its setting, though."
2203 :type 'boolean
2204 :group 'ps-print-face)
12d89a2e 2205
e0af0d3e 2206(defcustom ps-always-build-face-reference nil
12d89a2e
RS
2207 "*Non-nil means always rebuild the reference face lists.
2208
2209If this variable is non-nil, ps-print will rebuild its internal
2210reference lists of bold and italic faces *every* time one of the
496725ad 2211...-with-faces commands is called. Most users shouldn't need to set this
e0af0d3e
RS
2212variable."
2213 :type 'boolean
2214 :group 'ps-print-face)
ef2cbb24 2215
bc0d41bd
KH
2216(defcustom ps-banner-page-when-duplexing nil
2217 "*Non-nil means the very first page is skipped.
2218It's like the very first character of buffer (or region) is ^L (\\014)."
2219 :type 'boolean
6e1b1da6 2220 :group 'ps-print-headers)
bc0d41bd 2221
41481e4b
KH
2222(defcustom ps-postscript-code-directory data-directory
2223 "*Directory where it's located the PostScript prologue file used by ps-print.
2224By default, this directory is the same as in the variable `data-directory'."
2225 :type 'directory
6e1b1da6 2226 :group 'ps-print-miscellany)
41481e4b 2227
0a5daee5
KH
2228
2229;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2230;; Customization
2231
2232
2233;;;###autoload
2234(defun ps-print-customize ()
2235 "Customization of ps-print group."
2236 (interactive)
2237 (customize-group 'ps-print))
2238
2239
ef2cbb24 2240;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12d89a2e 2241;; User commands
ef2cbb24 2242
0a5daee5 2243
00aa16af 2244;;;###autoload
ef2cbb24 2245(defun ps-print-buffer (&optional filename)
12d89a2e 2246 "Generate and print a PostScript image of the buffer.
ef2cbb24 2247
5ac0cb14
RS
2248Interactively, when you use a prefix argument (C-u), the command
2249prompts the user for a file name, and saves the PostScript image
2250in that file instead of sending it to the printer.
ef2cbb24 2251
5ac0cb14 2252Noninteractively, the argument FILENAME is treated as follows: if it
ef2cbb24 2253is nil, send the image to the printer. If FILENAME is a string, save
79080fa0 2254the PostScript image in a file with that name."
00aa16af 2255 (interactive (list (ps-print-preprint current-prefix-arg)))
87a16a06 2256 (ps-print-without-faces (point-min) (point-max) filename))
ef2cbb24
RS
2257
2258
00aa16af 2259;;;###autoload
ef2cbb24 2260(defun ps-print-buffer-with-faces (&optional filename)
12d89a2e 2261 "Generate and print a PostScript image of the buffer.
12d89a2e 2262Like `ps-print-buffer', but includes font, color, and underline
107e7c70
KH
2263information in the generated image. This command works only if you
2264are using a window system, so it has a way to determine color values."
00aa16af 2265 (interactive (list (ps-print-preprint current-prefix-arg)))
87a16a06 2266 (ps-print-with-faces (point-min) (point-max) filename))
ef2cbb24 2267
ef2cbb24 2268
00aa16af 2269;;;###autoload
ef2cbb24 2270(defun ps-print-region (from to &optional filename)
12d89a2e 2271 "Generate and print a PostScript image of the region.
12d89a2e 2272Like `ps-print-buffer', but prints just the current region."
00aa16af 2273 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
a18ed129 2274 (ps-print-without-faces from to filename t))
ef2cbb24 2275
ef2cbb24 2276
00aa16af 2277;;;###autoload
ef2cbb24 2278(defun ps-print-region-with-faces (from to &optional filename)
12d89a2e 2279 "Generate and print a PostScript image of the region.
12d89a2e 2280Like `ps-print-region', but includes font, color, and underline
107e7c70
KH
2281information in the generated image. This command works only if you
2282are using a window system, so it has a way to determine color values."
00aa16af 2283 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
a18ed129 2284 (ps-print-with-faces from to filename t))
ef2cbb24 2285
ef2cbb24 2286
00aa16af 2287;;;###autoload
ef2cbb24 2288(defun ps-spool-buffer ()
12d89a2e 2289 "Generate and spool a PostScript image of the buffer.
12d89a2e
RS
2290Like `ps-print-buffer' except that the PostScript image is saved in a
2291local buffer to be sent to the printer later.
ef2cbb24 2292
12d89a2e 2293Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 2294 (interactive)
87a16a06 2295 (ps-spool-without-faces (point-min) (point-max)))
ef2cbb24 2296
ef2cbb24 2297
00aa16af 2298;;;###autoload
ef2cbb24 2299(defun ps-spool-buffer-with-faces ()
12d89a2e 2300 "Generate and spool a PostScript image of the buffer.
12d89a2e 2301Like `ps-spool-buffer', but includes font, color, and underline
107e7c70 2302information in the generated image. This command works only if you
1cd7962f 2303are using a window system, so it has a way to determine color values.
ef2cbb24 2304
12d89a2e 2305Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 2306 (interactive)
87a16a06 2307 (ps-spool-with-faces (point-min) (point-max)))
ef2cbb24 2308
ef2cbb24 2309
00aa16af 2310;;;###autoload
ef2cbb24 2311(defun ps-spool-region (from to)
12d89a2e 2312 "Generate a PostScript image of the region and spool locally.
12d89a2e 2313Like `ps-spool-buffer', but spools just the current region.
ef2cbb24 2314
12d89a2e 2315Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 2316 (interactive "r")
a18ed129 2317 (ps-spool-without-faces from to t))
ef2cbb24 2318
ef2cbb24 2319
00aa16af 2320;;;###autoload
ef2cbb24 2321(defun ps-spool-region-with-faces (from to)
12d89a2e 2322 "Generate a PostScript image of the region and spool locally.
12d89a2e 2323Like `ps-spool-region', but includes font, color, and underline
107e7c70 2324information in the generated image. This command works only if you
1cd7962f 2325are using a window system, so it has a way to determine color values.
ef2cbb24 2326
12d89a2e 2327Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 2328 (interactive "r")
a18ed129 2329 (ps-spool-with-faces from to t))
ef2cbb24 2330
00aa16af 2331;;;###autoload
ef2cbb24
RS
2332(defun ps-despool (&optional filename)
2333 "Send the spooled PostScript to the printer.
2334
79080fa0
RS
2335Interactively, when you use a prefix argument (C-u), the command
2336prompts the user for a file name, and saves the spooled PostScript
2337image in that file instead of sending it to the printer.
ef2cbb24 2338
298bfad9 2339Noninteractively, the argument FILENAME is treated as follows: if it
ef2cbb24 2340is nil, send the image to the printer. If FILENAME is a string, save
79080fa0 2341the PostScript image in a file with that name."
00aa16af
RS
2342 (interactive (list (ps-print-preprint current-prefix-arg)))
2343 (ps-do-despool filename))
12d89a2e 2344
bcc0d457
RS
2345;;;###autoload
2346(defun ps-line-lengths ()
06fb6aab 2347 "Display the correspondence between a line length and a font size,
bcc0d457
RS
2348using the current ps-print setup.
2349Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2350 (interactive)
2351 (ps-line-lengths-internal))
2352
2353;;;###autoload
2354(defun ps-nb-pages-buffer (nb-lines)
06fb6aab
RS
2355 "Display number of pages to print this buffer, for various font heights.
2356The table depends on the current ps-print setup."
bcc0d457
RS
2357 (interactive (list (count-lines (point-min) (point-max))))
2358 (ps-nb-pages nb-lines))
2359
2360;;;###autoload
2361(defun ps-nb-pages-region (nb-lines)
06fb6aab
RS
2362 "Display number of pages to print the region, for various font heights.
2363The table depends on the current ps-print setup."
bcc0d457
RS
2364 (interactive (list (count-lines (mark) (point))))
2365 (ps-nb-pages nb-lines))
2366
2367;;;###autoload
2368(defun ps-setup ()
496725ad 2369 "Return the current PostScript-generation setup."
a18ed129
RS
2370 (format
2371 "
bc0d41bd
KH
2372\(setq ps-print-color-p %s
2373 ps-lpr-command %S
2374 ps-lpr-switches %s
2375 ps-printer-name %S
2376 ps-print-region-function %s
bcc0d457 2377
7d8b7e8e 2378 ps-paper-type %s
8bd22fcf 2379 ps-landscape-mode %s
906d41a7 2380 ps-print-upside-down %s
8bd22fcf 2381 ps-number-of-columns %s
bcc0d457 2382
8bd22fcf 2383 ps-zebra-stripes %s
01961237 2384 ps-zebra-stripe-height %s
6e1b1da6 2385 ps-zebra-color %s
8bd22fcf 2386 ps-line-number %s
906d41a7 2387 ps-line-number-step %s
a18ed129 2388
6e1b1da6
GM
2389 ps-default-fg %s
2390 ps-default-bg %s
2391
906d41a7
GM
2392 ps-use-face-background %s
2393
7d8b7e8e 2394 ps-print-control-characters %s
d3ab8dac 2395
7d8b7e8e 2396 ps-print-background-image %s
857686a6 2397
7d8b7e8e 2398 ps-print-background-text %s
a18ed129 2399
66e63857
GM
2400 ps-error-handler-message %s
2401 ps-user-defined-prologue %s
7d8b7e8e 2402 ps-print-prologue-header %s
a18ed129 2403
bc0d41bd
KH
2404 ps-left-margin %s
2405 ps-right-margin %s
2406 ps-inter-column %s
2407 ps-bottom-margin %s
2408 ps-top-margin %s
2409 ps-header-offset %s
2410 ps-header-line-pad %s
2411 ps-print-header %s
2412 ps-print-only-one-header %s
2413 ps-print-header-frame %s
2414 ps-header-lines %s
2415 ps-show-n-of-n %s
2416 ps-spool-config %s
2417 ps-spool-duplex %s
2418 ps-spool-tumble %s
2419 ps-banner-page-when-duplexing %s
2420
2421 ps-n-up-printing %s
2422 ps-n-up-margin %s
2423 ps-n-up-border-p %s
2424 ps-n-up-filling %s
bcc0d457 2425
7d8b7e8e
KH
2426 ps-multibyte-buffer %s
2427 ps-font-family %s
a18ed129 2428 ps-font-size %s
7d8b7e8e 2429 ps-header-font-family %s
a18ed129
RS
2430 ps-header-font-size %s
2431 ps-header-title-font-size %s)
bcc0d457 2432"
a18ed129
RS
2433 ps-print-color-p
2434 ps-lpr-command
d3ab8dac
KH
2435 (ps-print-quote ps-lpr-switches)
2436 ps-printer-name
bc0d41bd 2437 (ps-print-quote ps-print-region-function)
d3ab8dac 2438 (ps-print-quote ps-paper-type)
a18ed129 2439 ps-landscape-mode
906d41a7 2440 ps-print-upside-down
a18ed129 2441 ps-number-of-columns
01961237
RS
2442 ps-zebra-stripes
2443 ps-zebra-stripe-height
6e1b1da6 2444 (ps-print-quote ps-zebra-color)
a18ed129 2445 ps-line-number
906d41a7 2446 (ps-print-quote ps-line-number-step)
6e1b1da6
GM
2447 (ps-print-quote ps-default-fg)
2448 (ps-print-quote ps-default-bg)
906d41a7 2449 (ps-print-quote ps-use-face-background)
d3ab8dac
KH
2450 (ps-print-quote ps-print-control-characters)
2451 (ps-print-quote ps-print-background-image)
2452 (ps-print-quote ps-print-background-text)
66e63857
GM
2453 (ps-print-quote ps-error-handler-message)
2454 (ps-print-quote ps-user-defined-prologue)
d3ab8dac 2455 (ps-print-quote ps-print-prologue-header)
a18ed129
RS
2456 ps-left-margin
2457 ps-right-margin
2458 ps-inter-column
2459 ps-bottom-margin
2460 ps-top-margin
2461 ps-header-offset
2462 ps-header-line-pad
2463 ps-print-header
d3ab8dac 2464 ps-print-only-one-header
a18ed129
RS
2465 ps-print-header-frame
2466 ps-header-lines
2467 ps-show-n-of-n
bc0d41bd 2468 (ps-print-quote ps-spool-config)
a18ed129 2469 ps-spool-duplex
bc0d41bd
KH
2470 ps-spool-tumble
2471 ps-banner-page-when-duplexing
2472 ps-n-up-printing
2473 ps-n-up-margin
2474 ps-n-up-border-p
2475 (ps-print-quote ps-n-up-filling)
0a5daee5 2476 (ps-print-quote ps-multibyte-buffer) ; see `ps-mule.el'
d3ab8dac 2477 (ps-print-quote ps-font-family)
7d8b7e8e 2478 (ps-print-quote ps-font-size)
d3ab8dac 2479 (ps-print-quote ps-header-font-family)
7d8b7e8e
KH
2480 (ps-print-quote ps-header-font-size)
2481 (ps-print-quote ps-header-title-font-size)))
bcc0d457 2482
0a5daee5 2483
12d89a2e
RS
2484;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2485;; Utility functions and variables:
2486
0a5daee5 2487
d3ab8dac 2488(defun ps-print-quote (sym)
7d8b7e8e
KH
2489 (cond ((null sym)
2490 nil)
2491 ((or (symbolp sym) (listp sym))
2492 (format "'%S" sym))
2493 ((stringp sym)
2494 (format "%S" sym))
2495 (t
d3ab8dac
KH
2496 sym)))
2497
6770a60f
RS
2498(defvar ps-print-emacs-type
2499 (cond ((string-match "XEmacs" emacs-version) 'xemacs)
2500 ((string-match "Lucid" emacs-version) 'lucid)
2501 ((string-match "Epoch" emacs-version) 'epoch)
2502 (t 'emacs)))
2503
2504(if (or (eq ps-print-emacs-type 'lucid)
2505 (eq ps-print-emacs-type 'xemacs))
043620f4
KH
2506 (if (< emacs-minor-version 12)
2507 (setq ps-print-color-p nil))
12d89a2e
RS
2508 (require 'faces)) ; face-font, face-underline-p,
2509 ; x-font-regexp
2510
857686a6
RS
2511;; Return t if the device (which can be changed during an emacs session)
2512;; can handle colors.
2513;; This is function is not yet implemented for GNU emacs.
e65df0a1
KH
2514(cond ((and (eq ps-print-emacs-type 'xemacs)
2515 (>= emacs-minor-version 12)) ; xemacs
2516 (defun ps-color-device ()
2517 (eq (device-class) 'color))
2518 )
2519
2520 (t ; emacs
2521 (defun ps-color-device ()
2522 t)
2523 ))
2524
857686a6 2525
12d89a2e
RS
2526(require 'time-stamp)
2527
bcc0d457 2528
41481e4b
KH
2529(defun ps-prologue-file (filenumber)
2530 (save-excursion
906d41a7
GM
2531 (let* ((filename (format "%sps-prin%d.ps"
2532 ps-postscript-code-directory filenumber))
2533 (buffer
2534 (or (find-file-noselect filename 'no-warn 'rawfile)
2535 (error "ps-print PostScript prologue `%s' file was not found."
2536 filename))))
41481e4b
KH
2537 (set-buffer buffer)
2538 (prog1
2539 (buffer-string)
2540 (kill-buffer buffer)))))
bcc0d457 2541
bcc0d457 2542
41481e4b 2543(defvar ps-mark-code-directory nil)
bcc0d457 2544
66e63857
GM
2545(defvar ps-print-prologue-0 ""
2546 "ps-print PostScript error handler.")
2547
41481e4b
KH
2548(defvar ps-print-prologue-1 ""
2549 "ps-print PostScript prologue begin.")
bcc0d457 2550
41481e4b
KH
2551(defvar ps-print-prologue-2 ""
2552 "ps-print PostScript prologue end.")
12d89a2e 2553
41481e4b
KH
2554(defvar ps-print-duplex-feature ""
2555 "ps-print PostScript duplex feature.")
bc0d41bd 2556
12d89a2e 2557;; Start Editing Here:
ef2cbb24 2558
12d89a2e
RS
2559(defvar ps-source-buffer nil)
2560(defvar ps-spool-buffer-name "*PostScript*")
2561(defvar ps-spool-buffer nil)
ef2cbb24 2562
12d89a2e
RS
2563(defvar ps-output-head nil)
2564(defvar ps-output-tail nil)
ef2cbb24 2565
7da17ab6 2566(defvar ps-page-postscript 0)
bc0d41bd 2567(defvar ps-page-order 0)
12d89a2e 2568(defvar ps-page-count 0)
87a16a06
RS
2569(defvar ps-showline-count 1)
2570
857686a6
RS
2571(defvar ps-control-or-escape-regexp nil)
2572
87a16a06
RS
2573(defvar ps-background-pages nil)
2574(defvar ps-background-all-pages nil)
2575(defvar ps-background-text-count 0)
2576(defvar ps-background-image-count 0)
ef2cbb24 2577
12d89a2e 2578(defvar ps-current-font 0)
6e1b1da6
GM
2579(defvar ps-default-foreground nil)
2580(defvar ps-default-color nil)
2581(defvar ps-current-color nil)
12d89a2e
RS
2582(defvar ps-current-bg nil)
2583
2584(defvar ps-razchunk 0)
2585
d3ab8dac 2586(defvar ps-color-p nil)
bcc0d457
RS
2587(defvar ps-color-format
2588 (if (eq ps-print-emacs-type 'emacs)
12d89a2e 2589
12b88fff
RS
2590 ;; Emacs understands the %f format; we'll use it to limit color RGB
2591 ;; values to three decimals to cut down some on the size of the
2592 ;; PostScript output.
2593 "%0.3f %0.3f %0.3f"
12d89a2e 2594
12b88fff 2595 ;; Lucid emacsen will have to make do with %s (princ) for floats.
bcc0d457 2596 "%s %s %s"))
12d89a2e
RS
2597
2598;; These values determine how much print-height to deduct when headers
2599;; are turned on. This is a pretty clumsy way of handling it, but
2600;; it'll do for now.
12d89a2e 2601
bcc0d457 2602(defvar ps-header-pad 0
496725ad
RS
2603 "Vertical and horizontal space between the header frame and the text.
2604This is in units of points (1/72 inch).")
12d89a2e 2605
bcc0d457 2606;; Define accessors to the dimensions list.
12d89a2e 2607
bcc0d457
RS
2608(defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims))
2609(defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
bc0d41bd 2610(defmacro ps-page-dimensions-get-media (dims) `(nth 2 ,dims))
12d89a2e 2611
87a16a06 2612(defvar ps-landscape-page-height nil)
12d89a2e 2613
12d89a2e
RS
2614(defvar ps-print-width nil)
2615(defvar ps-print-height nil)
2616
8bd22fcf
KH
2617(defvar ps-height-remaining nil)
2618(defvar ps-width-remaining nil)
12d89a2e 2619
bcc0d457
RS
2620(defvar ps-print-color-scale nil)
2621
7d8b7e8e
KH
2622(defvar ps-font-size-internal nil)
2623(defvar ps-header-font-size-internal nil)
2624(defvar ps-header-title-font-size-internal nil)
2625
87a16a06
RS
2626\f
2627;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2628;; Internal Variables
2629
2630
2631(defvar ps-print-face-extension-alist nil
a18ed129 2632 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
87a16a06
RS
2633An element of this list has the following form:
2634
2635 (FACE . [BITS FG BG])
2636
2637 FACE is a symbol denoting a face name
2638 BITS is a bit vector, where each bit correspond
2639 to a feature (bold, underline, etc)
2640 (see documentation for `ps-print-face-map-alist')
2641 FG foreground color (string or nil)
2642 BG background color (string or nil)
2643
a18ed129
RS
2644Don't change this list directly; instead,
2645use `ps-extend-face' and `ps-extend-face-list'.
2646See documentation for `ps-extend-face' for valid extension symbol.")
2647
2648
2649(defvar ps-print-face-alist nil
2650 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2651
2652An element of this list has the same form as an element of
2653`ps-print-face-extension-alist'.
2654
2655Don't change this list directly; this list is used by `ps-face-attributes',
2656`ps-map-face' and `ps-build-reference-face-lists'.")
87a16a06
RS
2657
2658
2659(defconst ps-print-face-map-alist
2660 '((bold . 1)
2661 (italic . 2)
2662 (underline . 4)
2663 (strikeout . 8)
2664 (overline . 16)
2665 (shadow . 32)
2666 (box . 64)
2667 (outline . 128))
2668 "Alist of all features and the corresponding bit mask.
2669Each symbol correspond to one bit in a bit vector.")
2670
2671\f
2672;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a18ed129 2673;; Remapping Faces
87a16a06
RS
2674
2675
2676;;;###autoload
2677(defun ps-extend-face-list (face-extension-list &optional merge-p)
2678 "Extend face in `ps-print-face-extension-alist'.
2679
a18ed129
RS
2680If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2681with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
87a16a06
RS
2682
2683The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2684
2685See `ps-extend-face' for documentation."
2686 (while face-extension-list
2687 (ps-extend-face (car face-extension-list) merge-p)
2688 (setq face-extension-list (cdr face-extension-list))))
2689
2690
2691;;;###autoload
2692(defun ps-extend-face (face-extension &optional merge-p)
2693 "Extend face in `ps-print-face-extension-alist'.
2694
6bdb808e 2695If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
a18ed129 2696with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
87a16a06
RS
2697
2698The elements of FACE-EXTENSION list have the form:
2699
2700 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2701
2702FACE-NAME is a face name symbol.
2703
2704FOREGROUND and BACKGROUND may be nil or a string that denotes the
2705foreground and background colors respectively.
2706
2707EXTENSION is one of the following symbols:
2708 bold - use bold font.
2709 italic - use italic font.
2710 underline - put a line under text.
2711 strikeout - like underline, but the line is in middle of text.
2712 overline - like underline, but the line is over the text.
2713 shadow - text will have a shadow.
2714 box - text will be surrounded by a box.
a18ed129 2715 outline - print characters as hollow outlines.
87a16a06
RS
2716
2717If EXTENSION is any other symbol, it is ignored."
2718 (let* ((face-name (nth 0 face-extension))
2719 (foreground (nth 1 face-extension))
2720 (background (nth 2 face-extension))
2721 (ps-face (cdr (assq face-name ps-print-face-extension-alist)))
2722 (face-vector (or ps-face (vector 0 nil nil)))
2723 (face-bit (ps-extension-bit face-extension)))
2724 ;; extend face
2725 (aset face-vector 0 (if merge-p
2726 (logior (aref face-vector 0) face-bit)
2727 face-bit))
2728 (and foreground (stringp foreground) (aset face-vector 1 foreground))
2729 (and background (stringp background) (aset face-vector 2 background))
2730 ;; if face does not exist, insert it
2731 (or ps-face
2732 (setq ps-print-face-extension-alist
2733 (cons (cons face-name face-vector)
2734 ps-print-face-extension-alist)))))
2735
2736
2737(defun ps-extension-bit (face-extension)
2738 (let ((face-bit 0))
2739 ;; map valid symbol extension to bit vector
2740 (setq face-extension (cdr (cdr face-extension)))
2741 (while (setq face-extension (cdr face-extension))
2742 (setq face-bit (logior face-bit
2743 (or (cdr (assq (car face-extension)
2744 ps-print-face-map-alist))
2745 0))))
2746 face-bit))
2747
2748\f
857686a6 2749;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bc0d41bd 2750;; Adapted from font-lock: (obsolete stuff)
857686a6
RS
2751;; Originally face attributes were specified via `font-lock-face-attributes'.
2752;; Users then changed the default face attributes by setting that variable.
2753;; However, we try and be back-compatible and respect its value if set except
2754;; for faces where M-x customize has been used to save changes for the face.
2755
0a5daee5 2756
857686a6
RS
2757(defun ps-font-lock-face-attributes ()
2758 (and (boundp 'font-lock-mode) (symbol-value 'font-lock-mode)
2759 (boundp 'font-lock-face-attributes)
2760 (let ((face-attributes font-lock-face-attributes))
2761 (while face-attributes
6bdb808e
RS
2762 (let* ((face-attribute
2763 (car (prog1 face-attributes
2764 (setq face-attributes (cdr face-attributes)))))
857686a6
RS
2765 (face (car face-attribute)))
2766 ;; Rustle up a `defface' SPEC from a
2767 ;; `font-lock-face-attributes' entry.
2768 (unless (get face 'saved-face)
2769 (let ((foreground (nth 1 face-attribute))
2770 (background (nth 2 face-attribute))
2771 (bold-p (nth 3 face-attribute))
2772 (italic-p (nth 4 face-attribute))
2773 (underline-p (nth 5 face-attribute))
2774 face-spec)
2775 (when foreground
2776 (setq face-spec (cons ':foreground
2777 (cons foreground face-spec))))
2778 (when background
2779 (setq face-spec (cons ':background
2780 (cons background face-spec))))
2781 (when bold-p
2782 (setq face-spec (append '(:bold t) face-spec)))
2783 (when italic-p
2784 (setq face-spec (append '(:italic t) face-spec)))
2785 (when underline-p
2786 (setq face-spec (append '(:underline t) face-spec)))
2787 (custom-declare-face face (list (list t face-spec)) nil)
2788 )))))))
2789
2790\f
87a16a06
RS
2791;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2792;; Internal functions and variables
2793
2794
12b88fff 2795(make-local-hook 'ps-print-hook)
bc0d41bd 2796(make-local-hook 'ps-print-begin-sheet-hook)
12b88fff
RS
2797(make-local-hook 'ps-print-begin-page-hook)
2798(make-local-hook 'ps-print-begin-column-hook)
2799
2800
a18ed129 2801(defun ps-print-without-faces (from to &optional filename region-p)
857686a6 2802 (ps-spool-without-faces from to region-p)
87a16a06
RS
2803 (ps-do-despool filename))
2804
2805
a18ed129 2806(defun ps-spool-without-faces (from to &optional region-p)
12b88fff 2807 (run-hooks 'ps-print-hook)
712dc9e0 2808 (ps-printing-region region-p from)
87a16a06
RS
2809 (ps-generate (current-buffer) from to 'ps-generate-postscript))
2810
2811
a18ed129 2812(defun ps-print-with-faces (from to &optional filename region-p)
857686a6 2813 (ps-spool-with-faces from to region-p)
87a16a06
RS
2814 (ps-do-despool filename))
2815
2816
a18ed129 2817(defun ps-spool-with-faces (from to &optional region-p)
12b88fff 2818 (run-hooks 'ps-print-hook)
712dc9e0 2819 (ps-printing-region region-p from)
87a16a06
RS
2820 (ps-generate (current-buffer) from to 'ps-generate-postscript-with-faces))
2821
2822
bc0d41bd 2823(defun ps-count-lines (from to)
a18ed129 2824 (+ (count-lines from to)
857686a6
RS
2825 (save-excursion
2826 (goto-char to)
2827 (if (= (current-column) 0) 1 0))))
87a16a06
RS
2828
2829
a18ed129 2830(defvar ps-printing-region nil
bc0d41bd
KH
2831 "Variable used to indicate if the region that ps-print is printing.
2832It is a cons, the car of which is the line number where the region begins, and
2833its cdr is the total number of lines in the buffer. Formatting functions can
2834use this information to print the original line number (and not the number of
2835lines printed), and to indicate in the header that the printout is of a partial
2836file.")
2837
2838
2839(defvar ps-printing-region-p nil
2840 "Non-nil means ps-print is printing a region.")
87a16a06
RS
2841
2842
712dc9e0 2843(defun ps-printing-region (region-p from)
bc0d41bd
KH
2844 (setq ps-printing-region-p region-p
2845 ps-printing-region
2846 (cons (if region-p
712dc9e0 2847 (ps-count-lines (point-min) from)
bc0d41bd
KH
2848 1)
2849 (ps-count-lines (point-min) (point-max)))))
87a16a06
RS
2850
2851\f
12d89a2e
RS
2852;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2853;; Internal functions
2854
0a5daee5 2855
7ae35a2f 2856(defsubst ps-font-alist (font-sym)
12b88fff
RS
2857 (get font-sym 'fonts))
2858
2859(defun ps-font (font-sym font-type)
2860 "Font family name for text of `font-type', when generating PostScript."
7ae35a2f 2861 (let* ((font-list (ps-font-alist font-sym))
12b88fff 2862 (normal-font (cdr (assq 'normal font-list))))
6bdb808e
RS
2863 (while (and font-list (not (eq font-type (car (car font-list)))))
2864 (setq font-list (cdr font-list)))
2865 (or (cdr (car font-list)) normal-font)))
12b88fff
RS
2866
2867(defun ps-fonts (font-sym)
7ae35a2f 2868 (mapcar 'cdr (ps-font-alist font-sym)))
12b88fff
RS
2869
2870(defun ps-font-number (font-sym font-type)
7ae35a2f 2871 (or (ps-alist-position font-type (ps-font-alist font-sym))
12b88fff
RS
2872 0))
2873
2874(defsubst ps-line-height (font-sym)
2875 "The height of a line, for generating PostScript.
2876This is the value that ps-print uses to determine the height,
2877y-dimension, of the lines of text it has printed, and thus affects the
2878point at which page-breaks are placed.
2879The line-height is *not* the same as the point size of the font."
2880 (get font-sym 'line-height))
2881
2882(defsubst ps-title-line-height (font-sym)
2883 "The height of a `title' line, for generating PostScript.
2884This is the value that ps-print uses to determine the height,
2885y-dimension, of the lines of text it has printed, and thus affects the
2886point at which page-breaks are placed.
2887The title-line-height is *not* the same as the point size of the font."
2888 (get font-sym 'title-line-height))
2889
2890(defsubst ps-space-width (font-sym)
2891 "The width of a space character, for generating PostScript.
2892This value is used in expanding tab characters."
2893 (get font-sym 'space-width))
2894
2895(defsubst ps-avg-char-width (font-sym)
2896 "The average width, in points, of a character, for generating PostScript.
2897This is the value that ps-print uses to determine the length,
2898x-dimension, of the text it has printed, and thus affects the point at
2899which long lines wrap around."
2900 (get font-sym 'avg-char-width))
2901
bcc0d457 2902(defun ps-line-lengths-internal ()
87a16a06 2903 "Display the correspondence between a line length and a font size,
bcc0d457
RS
2904using the current ps-print setup.
2905Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2906 (let ((buf (get-buffer-create "*Line-lengths*"))
7d8b7e8e 2907 (ifs ps-font-size-internal) ; initial font size
12b88fff 2908 (icw (ps-avg-char-width 'ps-font-for-text)) ; initial character width
bcc0d457
RS
2909 (print-width (progn (ps-get-page-dimensions)
2910 ps-print-width))
2911 (ps-setup (ps-setup)) ; setup for the current buffer
2912 (fs-min 5) ; minimum font size
2913 cw-min ; minimum character width
2914 nb-cpl-max ; maximum nb of characters per line
2915 (fs-max 14) ; maximum font size
2916 cw-max ; maximum character width
2917 nb-cpl-min ; minimum nb of characters per line
2918 fs ; current font size
2919 cw ; current character width
2920 nb-cpl ; current nb of characters per line
2921 )
2922 (setq cw-min (/ (* icw fs-min) ifs)
2923 nb-cpl-max (floor (/ print-width cw-min))
2924 cw-max (/ (* icw fs-max) ifs)
8bd22fcf
KH
2925 nb-cpl-min (floor (/ print-width cw-max))
2926 nb-cpl nb-cpl-min)
bcc0d457
RS
2927 (set-buffer buf)
2928 (goto-char (point-max))
8bd22fcf
KH
2929 (or (bolp) (insert "\n"))
2930 (insert ps-setup
2931 "nb char per line / font size\n")
bcc0d457 2932 (while (<= nb-cpl nb-cpl-max)
8bd22fcf
KH
2933 (setq cw (/ print-width (float nb-cpl))
2934 fs (/ (* ifs cw) icw))
bcc0d457
RS
2935 (insert (format "%3s %s\n" nb-cpl fs))
2936 (setq nb-cpl (1+ nb-cpl)))
2937 (insert "\n")
2938 (display-buffer buf 'not-this-window)))
2939
2940(defun ps-nb-pages (nb-lines)
496725ad
RS
2941 "Display correspondence between font size and the number of pages.
2942The correspondence is based on having NB-LINES lines of text,
2943and on the current ps-print setup."
bcc0d457 2944 (let ((buf (get-buffer-create "*Nb-Pages*"))
7d8b7e8e 2945 (ifs ps-font-size-internal) ; initial font size
12b88fff 2946 (ilh (ps-line-height 'ps-font-for-text)) ; initial line height
bcc0d457
RS
2947 (page-height (progn (ps-get-page-dimensions)
2948 ps-print-height))
2949 (ps-setup (ps-setup)) ; setup for the current buffer
2950 (fs-min 4) ; minimum font size
2951 lh-min ; minimum line height
2952 nb-lpp-max ; maximum nb of lines per page
2953 nb-page-min ; minimum nb of pages
2954 (fs-max 14) ; maximum font size
2955 lh-max ; maximum line height
2956 nb-lpp-min ; minimum nb of lines per page
2957 nb-page-max ; maximum nb of pages
2958 fs ; current font size
2959 lh ; current line height
2960 nb-lpp ; current nb of lines per page
2961 nb-page ; current nb of pages
2962 )
2963 (setq lh-min (/ (* ilh fs-min) ifs)
2964 nb-lpp-max (floor (/ page-height lh-min))
2965 nb-page-min (ceiling (/ (float nb-lines) nb-lpp-max))
2966 lh-max (/ (* ilh fs-max) ifs)
2967 nb-lpp-min (floor (/ page-height lh-max))
8bd22fcf
KH
2968 nb-page-max (ceiling (/ (float nb-lines) nb-lpp-min))
2969 nb-page nb-page-min)
bcc0d457
RS
2970 (set-buffer buf)
2971 (goto-char (point-max))
8bd22fcf
KH
2972 (or (bolp) (insert "\n"))
2973 (insert ps-setup
2974 (format "%d lines\n" nb-lines)
2975 "nb page / font size\n")
bcc0d457
RS
2976 (while (<= nb-page nb-page-max)
2977 (setq nb-lpp (ceiling (/ nb-lines (float nb-page)))
2978 lh (/ page-height nb-lpp)
2979 fs (/ (* ifs lh) ilh))
2980 (insert (format "%s %s\n" nb-page fs))
2981 (setq nb-page (1+ nb-page)))
2982 (insert "\n")
2983 (display-buffer buf 'not-this-window)))
2984
6bdb808e
RS
2985;; macros used in `ps-select-font'
2986(defmacro ps-lookup (key) `(cdr (assq ,key font-entry)))
2987(defmacro ps-size-scale (key) `(/ (* (ps-lookup ,key) font-size) size))
2988
12b88fff
RS
2989(defun ps-select-font (font-family sym font-size title-font-size)
2990 (let ((font-entry (cdr (assq font-family ps-font-info-database))))
2991 (or font-entry
2992 (error "Don't have data to scale font %s. Known fonts families are %s"
2993 font-family
2994 (mapcar 'car ps-font-info-database)))
6bdb808e
RS
2995 (let ((size (ps-lookup 'size)))
2996 (put sym 'fonts (ps-lookup 'fonts))
2997 (put sym 'space-width (ps-size-scale 'space-width))
2998 (put sym 'avg-char-width (ps-size-scale 'avg-char-width))
2999 (put sym 'line-height (ps-size-scale 'line-height))
3000 (put sym 'title-line-height
3001 (/ (* (ps-lookup 'line-height) title-font-size) size)))))
bcc0d457 3002
12d89a2e 3003(defun ps-get-page-dimensions ()
bcc0d457
RS
3004 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
3005 page-width page-height)
3006 (cond
3007 ((null page-dimensions)
3008 (error "`ps-paper-type' must be one of:\n%s"
3009 (mapcar 'car ps-page-dimensions-database)))
3010 ((< ps-number-of-columns 1)
12b88fff 3011 (error "The number of columns %d should be positive"
8bd22fcf 3012 ps-number-of-columns)))
bcc0d457 3013
12b88fff 3014 (ps-select-font ps-font-family 'ps-font-for-text
7d8b7e8e 3015 ps-font-size-internal ps-font-size-internal)
12b88fff 3016 (ps-select-font ps-header-font-family 'ps-font-for-header
7d8b7e8e
KH
3017 ps-header-font-size-internal
3018 ps-header-title-font-size-internal)
bcc0d457
RS
3019
3020 (setq page-width (ps-page-dimensions-get-width page-dimensions)
3021 page-height (ps-page-dimensions-get-height page-dimensions))
3022
3023 ;; Landscape mode
3024 (if ps-landscape-mode
3025 ;; exchange width and height
3026 (setq page-width (prog1 page-height (setq page-height page-width))))
3027
3028 ;; It is used to get the lower right corner (only in landscape mode)
3029 (setq ps-landscape-page-height page-height)
3030
3031 ;; | lm | text | ic | text | ic | text | rm |
3032 ;; page-width == lm + n * pw + (n - 1) * ic + rm
3033 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
8bd22fcf
KH
3034 (setq ps-print-width (/ (- page-width
3035 ps-left-margin ps-right-margin
3036 (* (1- ps-number-of-columns) ps-inter-column))
3037 ps-number-of-columns))
bcc0d457
RS
3038 (if (<= ps-print-width 0)
3039 (error "Bad horizontal layout:
3040page-width == %s
3041ps-left-margin == %s
3042ps-right-margin == %s
3043ps-inter-column == %s
3044ps-number-of-columns == %s
3045| lm | text | ic | text | ic | text | rm |
3046page-width == lm + n * print-width + (n - 1) * ic + rm
3047=> print-width == %d !"
3048 page-width
3049 ps-left-margin
3050 ps-right-margin
3051 ps-inter-column
3052 ps-number-of-columns
3053 ps-print-width))
3054
3055 (setq ps-print-height
3056 (- page-height ps-bottom-margin ps-top-margin))
3057 (if (<= ps-print-height 0)
3058 (error "Bad vertical layout:
3059ps-top-margin == %s
3060ps-bottom-margin == %s
3061page-height == bm + print-height + tm
3062=> print-height == %d !"
3063 ps-top-margin
3064 ps-bottom-margin
3065 ps-print-height))
3066 ;; If headers are turned on, deduct the height of the header from
3067 ;; the print height.
8bd22fcf 3068 (if ps-print-header
12b88fff
RS
3069 (setq ps-header-pad (* ps-header-line-pad
3070 (ps-title-line-height 'ps-font-for-header))
8bd22fcf
KH
3071 ps-print-height (- ps-print-height
3072 ps-header-offset
3073 ps-header-pad
12b88fff
RS
3074 (ps-title-line-height 'ps-font-for-header)
3075 (* (ps-line-height 'ps-font-for-header)
3076 (1- ps-header-lines))
8bd22fcf 3077 ps-header-pad)))
bcc0d457
RS
3078 (if (<= ps-print-height 0)
3079 (error "Bad vertical layout:
3080ps-top-margin == %s
3081ps-bottom-margin == %s
3082ps-header-offset == %s
3083ps-header-pad == %s
3084header-height == %s
3085page-height == bm + print-height + tm - ho - hh
3086=> print-height == %d !"
3087 ps-top-margin
3088 ps-bottom-margin
3089 ps-header-offset
3090 ps-header-pad
3091 (+ ps-header-pad
12b88fff
RS
3092 (ps-title-line-height 'ps-font-for-header)
3093 (* (ps-line-height 'ps-font-for-header)
3094 (1- ps-header-lines))
bcc0d457
RS
3095 ps-header-pad)
3096 ps-print-height))))
ef2cbb24 3097
edc9cd35
GM
3098(defun ps-print-preprint (prefix-arg)
3099 (and prefix-arg
3100 (or (numberp prefix-arg)
3101 (listp prefix-arg))
d3ab8dac
KH
3102 (let* ((name (concat (file-name-nondirectory (or (buffer-file-name)
3103 (buffer-name)))
3104 ".ps"))
8bd22fcf
KH
3105 (prompt (format "Save PostScript to file: (default %s) " name))
3106 (res (read-file-name prompt default-directory name nil)))
d3ab8dac
KH
3107 (while (cond ((not (file-writable-p res))
3108 (ding)
3109 (setq prompt "is unwritable"))
3110 ((file-exists-p res)
3111 (setq prompt "exists")
3112 (not (y-or-n-p (format "File `%s' exists; overwrite? "
3113 res))))
3114 (t nil))
3115 (setq res (read-file-name
3116 (format "File %s; save PostScript to file: " prompt)
3117 (file-name-directory res) nil nil
3118 (file-name-nondirectory res))))
8bd22fcf
KH
3119 (if (file-directory-p res)
3120 (expand-file-name name (file-name-as-directory res))
3121 res))))
12d89a2e
RS
3122
3123;; The following functions implement a simple list-buffering scheme so
3124;; that ps-print doesn't have to repeatedly switch between buffers
857686a6
RS
3125;; while spooling. The functions `ps-output' and `ps-output-string' build
3126;; up the lists; the function `ps-flush-output' takes the lists and
12d89a2e
RS
3127;; insert its contents into the spool buffer (*PostScript*).
3128
857686a6
RS
3129(defvar ps-string-escape-codes
3130 (let ((table (make-vector 256 nil))
3131 (char ?\000))
3132 ;; control characters
3133 (while (<= char ?\037)
3134 (aset table char (format "\\%03o" char))
3135 (setq char (1+ char)))
3136 ;; printable characters
3137 (while (< char ?\177)
3138 (aset table char (format "%c" char))
3139 (setq char (1+ char)))
3140 ;; DEL and 8-bit characters
3141 (while (<= char ?\377)
3142 (aset table char (format "\\%o" char))
3143 (setq char (1+ char)))
3144 ;; Override ASCII formatting characters with named escape code:
3145 (aset table ?\n "\\n") ; [NL] linefeed
3146 (aset table ?\r "\\r") ; [CR] carriage return
3147 (aset table ?\t "\\t") ; [HT] horizontal tab
3148 (aset table ?\b "\\b") ; [BS] backspace
3149 (aset table ?\f "\\f") ; [NP] form feed
3150 ;; Escape PostScript escape and string delimiter characters:
3151 (aset table ?\\ "\\\\")
3152 (aset table ?\( "\\(")
3153 (aset table ?\) "\\)")
3154 table)
3155 "Vector used to map characters to PostScript string escape codes.")
3156
12d89a2e
RS
3157(defun ps-output-string-prim (string)
3158 (insert "(") ;insert start-string delimiter
3159 (save-excursion ;insert string
e65df0a1 3160 (insert (string-as-unibyte string)))
12d89a2e 3161 ;; Find and quote special characters as necessary for PS
c82b4a75 3162 ;; This skips everything except control chars, non-ASCII chars, (, ) and \.
b61e2c11
RS
3163 (while (progn (skip-chars-forward " -'*-[]-~") (not (eobp)))
3164 (let ((special (following-char)))
e65df0a1
KH
3165 (delete-char 1)
3166 (insert (aref ps-string-escape-codes special))))
12d89a2e
RS
3167 (goto-char (point-max))
3168 (insert ")")) ;insert end-string delimiter
ef2cbb24 3169
12d89a2e 3170(defun ps-init-output-queue ()
8bd22fcf
KH
3171 (setq ps-output-head '("")
3172 ps-output-tail ps-output-head))
ef2cbb24 3173
12d89a2e
RS
3174(defun ps-output (&rest args)
3175 (setcdr ps-output-tail args)
3176 (while (cdr ps-output-tail)
3177 (setq ps-output-tail (cdr ps-output-tail))))
ef2cbb24 3178
12d89a2e
RS
3179(defun ps-output-string (string)
3180 (ps-output t string))
ef2cbb24 3181
87a16a06
RS
3182(defun ps-output-list (the-list)
3183 (mapcar 'ps-output the-list))
3184
e65df0a1
KH
3185;; Output strings in the list ARGS in the PostScript prologue part.
3186(defun ps-output-prologue (args)
3187 (ps-output 'prologue (if (stringp args) (list args) args)))
3188
12d89a2e
RS
3189(defun ps-flush-output ()
3190 (save-excursion
3191 (set-buffer ps-spool-buffer)
3192 (goto-char (point-max))
3193 (while ps-output-head
3194 (let ((it (car ps-output-head)))
e65df0a1
KH
3195 (cond
3196 ((eq t it)
3197 (setq ps-output-head (cdr ps-output-head))
3198 (ps-output-string-prim (car ps-output-head)))
3199 ((eq 'prologue it)
12d89a2e 3200 (setq ps-output-head (cdr ps-output-head))
e65df0a1
KH
3201 (save-excursion
3202 (search-backward "\nBeginDoc")
3203 (forward-char 1)
3204 (apply 'insert (car ps-output-head))))
3205 (t
3206 (insert it))))
12d89a2e
RS
3207 (setq ps-output-head (cdr ps-output-head))))
3208 (ps-init-output-queue))
3209
3210(defun ps-insert-file (fname)
3211 (ps-flush-output)
12d89a2e
RS
3212 (save-excursion
3213 (set-buffer ps-spool-buffer)
3214 (goto-char (point-max))
3215 (insert-file fname)))
06fb6aab 3216
12d89a2e
RS
3217;; These functions insert the arrays that define the contents of the
3218;; headers.
ef2cbb24 3219
12d89a2e
RS
3220(defun ps-generate-header-line (fonttag &optional content)
3221 (ps-output " [ " fonttag " ")
3222 (cond
3223 ;; Literal strings should be output as is -- the string must
3224 ;; contain its own PS string delimiters, '(' and ')', if necessary.
3225 ((stringp content)
3226 (ps-output content))
3227
3228 ;; Functions are called -- they should return strings; they will be
3229 ;; inserted as strings and the PS string delimiters added.
3230 ((and (symbolp content) (fboundp content))
3231 (ps-output-string (funcall content)))
3232
3233 ;; Variables will have their contents inserted. They should
3234 ;; contain strings, and will be inserted as strings.
3235 ((and (symbolp content) (boundp content))
3236 (ps-output-string (symbol-value content)))
3237
3238 ;; Anything else will get turned into an empty string.
3239 (t
3240 (ps-output-string "")))
3241 (ps-output " ]\n"))
3242
3243(defun ps-generate-header (name contents)
3244 (ps-output "/" name " [\n")
3245 (if (> ps-header-lines 0)
3246 (let ((count 1))
3247 (ps-generate-header-line "/h0" (car contents))
3248 (while (and (< count ps-header-lines)
3249 (setq contents (cdr contents)))
3250 (ps-generate-header-line "/h1" (car contents))
8bd22fcf 3251 (setq count (1+ count)))
12d89a2e
RS
3252 (ps-output "] def\n"))))
3253
bc0d41bd 3254
6e1b1da6
GM
3255(defun ps-output-boolean (name bool)
3256 (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
ef2cbb24 3257
06fb6aab 3258
87a16a06
RS
3259(defun ps-background-pages (page-list func)
3260 (if page-list
3261 (mapcar
bc0d41bd
KH
3262 #'(lambda (pages)
3263 (let ((start (if (consp pages) (car pages) pages))
3264 (end (if (consp pages) (cdr pages) pages)))
3265 (and (integerp start) (integerp end) (<= start end)
3266 (add-to-list 'ps-background-pages (vector start end func)))))
87a16a06
RS
3267 page-list)
3268 (setq ps-background-all-pages (cons func ps-background-all-pages))))
3269
3270
bc0d41bd
KH
3271(defconst ps-boundingbox-re
3272 "^%%BoundingBox:\
3273\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)")
3274
3275
87a16a06
RS
3276(defun ps-get-boundingbox ()
3277 (save-excursion
3278 (set-buffer ps-spool-buffer)
3279 (save-excursion
bc0d41bd 3280 (if (re-search-forward ps-boundingbox-re nil t)
87a16a06
RS
3281 (vector (string-to-number ; lower x
3282 (buffer-substring (match-beginning 1) (match-end 1)))
3283 (string-to-number ; lower y
3284 (buffer-substring (match-beginning 2) (match-end 2)))
3285 (string-to-number ; upper x
3286 (buffer-substring (match-beginning 3) (match-end 3)))
3287 (string-to-number ; upper y
3288 (buffer-substring (match-beginning 4) (match-end 4))))
3289 (vector 0 0 0 0)))))
3290
3291
3292;; Emacs understands the %f format; we'll use it to limit color RGB values
3293;; to three decimals to cut down some on the size of the PostScript output.
3294;; Lucid emacsen will have to make do with %s (princ) for floats.
3295
3296(defvar ps-float-format (if (eq ps-print-emacs-type 'emacs)
3297 "%0.3f " ; emacs
3298 "%s ")) ; Lucid emacsen
3299
3300
3301(defun ps-float-format (value &optional default)
3302 (let ((literal (or value default)))
3303 (if literal
3304 (format (if (numberp literal)
3305 ps-float-format
3306 "%s ")
3307 literal)
3308 " ")))
3309
3310
3311(defun ps-background-text ()
3312 (mapcar
bc0d41bd
KH
3313 #'(lambda (text)
3314 (setq ps-background-text-count (1+ ps-background-text-count))
3315 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count))
3316 (ps-output-string (nth 0 text)) ; text
3317 (ps-output
3318 "\n"
3319 (ps-float-format (nth 4 text) 200.0) ; font size
3320 (format "/%s " (or (nth 3 text) "Times-Roman")) ; font name
3321 (ps-float-format (nth 6 text)
3322 "PrintHeight PrintPageWidth atan") ; rotation
3323 (ps-float-format (nth 5 text) 0.85) ; gray
3324 (ps-float-format (nth 1 text) "0") ; x position
3325 (ps-float-format (nth 2 text) "BottomMargin") ; y position
3326 "\nShowBackText} def\n")
3327 (ps-background-pages (nthcdr 7 text) ; page list
3328 (format "ShowBackText-%d\n"
3329 ps-background-text-count)))
87a16a06
RS
3330 ps-print-background-text))
3331
3332
3333(defun ps-background-image ()
3334 (mapcar
bc0d41bd
KH
3335 #'(lambda (image)
3336 (let ((image-file (expand-file-name (nth 0 image))))
41481e4b
KH
3337 (when (file-readable-p image-file)
3338 (setq ps-background-image-count (1+ ps-background-image-count))
3339 (ps-output
3340 (format "/ShowBackImage-%d {\n--back-- "
3341 ps-background-image-count)
3342 (ps-float-format (nth 5 image) 0.0) ; rotation
3343 (ps-float-format (nth 3 image) 1.0) ; x scale
3344 (ps-float-format (nth 4 image) 1.0) ; y scale
3345 (ps-float-format (nth 1 image) ; x position
3346 "PrintPageWidth 2 div")
3347 (ps-float-format (nth 2 image) ; y position
3348 "PrintHeight 2 div BottomMargin add")
3349 "\nBeginBackImage\n")
3350 (ps-insert-file image-file)
3351 ;; coordinate adjustment to centralize image
3352 ;; around x and y position
3353 (let ((box (ps-get-boundingbox)))
3354 (save-excursion
3355 (set-buffer ps-spool-buffer)
3356 (save-excursion
3357 (if (re-search-backward "^--back--" nil t)
3358 (replace-match
3359 (format "%s %s"
3360 (ps-float-format
3361 (- (+ (/ (- (aref box 2) (aref box 0)) 2.0)
3362 (aref box 0))))
3363 (ps-float-format
3364 (- (+ (/ (- (aref box 3) (aref box 1)) 2.0)
3365 (aref box 1)))))
3366 t)))))
3367 (ps-output "\nEndBackImage} def\n")
3368 (ps-background-pages (nthcdr 6 image) ; page list
3369 (format "ShowBackImage-%d\n"
3370 ps-background-image-count)))))
87a16a06
RS
3371 ps-print-background-image))
3372
3373
a18ed129 3374(defun ps-background (page-number)
87a16a06 3375 (let (has-local-background)
bc0d41bd
KH
3376 (mapcar #'(lambda (range)
3377 (and (<= (aref range 0) page-number)
3378 (<= page-number (aref range 1))
3379 (if has-local-background
3380 (ps-output (aref range 2))
3381 (setq has-local-background t)
3382 (ps-output "/printLocalBackground {\n"
3383 (aref range 2)))))
87a16a06
RS
3384 ps-background-pages)
3385 (and has-local-background (ps-output "} def\n"))))
3386
3387
0140c600
EZ
3388;; Return a list of the distinct elements of LIST.
3389;; Elements are compared with `equal'.
3390(defun ps-remove-duplicates (list)
3391 (let (new (tail list))
3392 (while tail
3393 (or (member (car tail) new)
3394 (setq new (cons (car tail) new)))
3395 (setq tail (cdr tail)))
3396 (nreverse new)))
3397
c82b4a75 3398
6bdb808e
RS
3399;; Find the first occurrence of ITEM in LIST.
3400;; Return the index of the matching item, or nil if not found.
3401;; Elements are compared with `eq'.
7ae35a2f 3402(defun ps-alist-position (item list)
6bdb808e
RS
3403 (let ((tail list) (index 0) found)
3404 (while tail
7ae35a2f 3405 (if (setq found (eq (car (car tail)) item))
6bdb808e
RS
3406 (setq tail nil)
3407 (setq index (1+ index)
3408 tail (cdr tail))))
3409 (and found index)))
3410
3411
bc0d41bd
KH
3412(defconst ps-n-up-database
3413 '((a4
3414 (1 nil 1 1 0)
3415 (2 t 1 2 0)
3416 (4 nil 2 2 0)
3417 (6 t 2 3 1)
3418 (8 t 2 4 0)
3419 (9 nil 3 3 0)
3420 (12 t 3 4 2)
3421 (16 nil 4 4 0)
3422 (18 t 3 6 0)
3423 (20 nil 5 4 1)
3424 (25 nil 5 5 0)
3425 (30 nil 6 5 1)
3426 (32 t 4 8 0)
3427 (36 nil 6 6 0)
3428 (42 nil 7 6 1)
3429 (49 nil 7 7 0)
3430 (50 t 5 10 0)
3431 (56 nil 8 7 1)
3432 (64 nil 8 8 0)
3433 (72 nil 9 8 1)
3434 (81 nil 9 9 0)
3435 (90 nil 10 9 1)
3436 (100 nil 10 10 0))
3437 (a3
3438 (1 nil 1 1 0)
3439 (2 t 1 2 0)
3440 (4 nil 2 2 0)
3441 (6 t 2 3 1)
3442 (8 t 2 4 0)
3443 (9 nil 3 3 0)
3444 (12 nil 4 3 1)
3445 (16 nil 4 4 0)
3446 (18 t 3 6 0)
3447 (20 nil 5 4 1)
3448 (25 nil 5 5 0)
3449 (30 nil 6 5 1)
3450 (32 t 4 8 0)
3451 (36 nil 6 6 0)
3452 (42 nil 7 6 1)
3453 (49 nil 7 7 0)
3454 (50 t 5 10 0)
3455 (56 nil 8 7 1)
3456 (64 nil 8 8 0)
3457 (72 nil 9 8 1)
3458 (81 nil 9 9 0)
3459 (90 nil 10 9 1)
3460 (100 nil 10 10 0))
3461 (letter
3462 (1 nil 1 1 0)
3463 (4 nil 2 2 0)
3464 (6 t 2 3 0)
3465 (9 nil 3 3 0)
3466 (12 nil 4 3 1)
3467 (16 nil 4 4 0)
3468 (20 nil 5 4 1)
3469 (25 nil 5 5 0)
3470 (30 nil 6 5 1)
3471 (36 nil 6 6 0)
3472 (40 t 5 8 0)
3473 (42 nil 7 6 1)
3474 (49 nil 7 7 0)
3475 (56 nil 8 7 1)
3476 (64 nil 8 8 0)
3477 (72 nil 9 8 1)
3478 (81 nil 9 9 0)
3479 (90 nil 10 9 1)
3480 (100 nil 10 10 0))
3481 (legal
3482 (1 nil 1 1 0)
3483 (2 t 1 2 0)
3484 (4 nil 2 2 0)
3485 (6 nil 3 2 1)
3486 (9 nil 3 3 0)
3487 (10 t 2 5 0)
3488 (12 nil 4 3 1)
3489 (16 nil 4 4 0)
3490 (20 nil 5 4 1)
3491 (25 nil 5 5 0)
3492 (30 nil 6 5 1)
3493 (36 nil 6 6 0)
3494 (42 nil 7 6 1)
3495 (49 nil 7 7 0)
3496 (56 nil 8 7 1)
3497 (64 nil 8 8 0)
3498 (70 t 5 14 0)
3499 (72 nil 9 8 1)
3500 (81 nil 9 9 0)
3501 (90 nil 10 9 1)
3502 (100 nil 10 10 0))
3503 (letter-small
3504 (1 nil 1 1 0)
3505 (4 nil 2 2 0)
3506 (6 t 2 3 0)
3507 (9 nil 3 3 0)
3508 (12 t 3 4 1)
3509 (15 t 3 5 0)
3510 (16 nil 4 4 0)
3511 (20 nil 5 4 1)
3512 (25 nil 5 5 0)
3513 (28 t 4 7 0)
3514 (30 nil 6 5 1)
3515 (36 nil 6 6 0)
3516 (40 t 5 8 0)
3517 (42 nil 7 6 1)
3518 (49 nil 7 7 0)
3519 (56 nil 8 7 1)
3520 (60 t 6 10 0)
3521 (64 nil 8 8 0)
3522 (72 ni 9 8 1)
3523 (81 nil 9 9 0)
3524 (84 t 7 12 0)
3525 (90 nil 10 9 1)
3526 (100 nil 10 10 0))
3527 (tabloid
3528 (1 nil 1 1 0)
3529 (2 t 1 2 0)
3530 (4 nil 2 2 0)
3531 (6 t 2 3 1)
3532 (8 t 2 4 0)
3533 (9 nil 3 3 0)
3534 (12 nil 4 3 1)
3535 (16 nil 4 4 0)
3536 (20 nil 5 4 1)
3537 (25 nil 5 5 0)
3538 (30 nil 6 5 1)
3539 (36 nil 6 6 0)
3540 (42 nil 7 6 1)
3541 (49 nil 7 7 0)
3542 (56 nil 8 7 1)
3543 (64 nil 8 8 0)
3544 (72 nil 9 8 1)
3545 (81 nil 9 9 0)
3546 (84 t 6 14 0)
3547 (90 nil 10 9 1)
3548 (100 nil 10 10 0))
3549 ;; Ledger paper size is a special case, it is the only paper size where the
3550 ;; normal size is landscaped, that is, the height is smaller than width.
3551 ;; So, we use the special value `pag' in the `landscape' field.
3552 (ledger
3553 (1 nil 1 1 0)
3554 (2 pag 1 2 0)
3555 (4 nil 2 2 0)
3556 (6 pag 2 3 1)
3557 (8 pag 2 4 0)
3558 (9 nil 3 3 0)
3559 (12 nil 4 3 1)
3560 (16 nil 4 4 0)
3561 (20 nil 5 4 1)
3562 (25 nil 5 5 0)
3563 (30 nil 6 5 1)
3564 (36 nil 6 6 0)
3565 (42 nil 7 6 1)
3566 (49 nil 7 7 0)
3567 (56 nil 8 7 1)
3568 (64 nil 8 8 0)
3569 (72 nil 9 8 1)
3570 (81 nil 9 9 0)
3571 (84 pag 6 14 0)
3572 (90 nil 10 9 1)
3573 (100 nil 10 10 0))
3574 (statement
3575 (1 nil 1 1 0)
3576 (2 t 1 2 0)
3577 (4 nil 2 2 0)
3578 (6 nil 3 2 1)
3579 (9 nil 3 3 0)
3580 (10 t 2 5 0)
3581 (12 nil 4 3 1)
3582 (16 nil 4 4 0)
3583 (20 nil 5 4 1)
3584 (21 t 3 7 0)
3585 (25 nil 5 5 0)
3586 (30 nil 6 5 1)
3587 (36 nil 6 6 0)
3588 (40 t 4 10 0)
3589 (42 nil 7 6 1)
3590 (49 nil 7 7 0)
3591 (56 nil 8 7 1)
3592 (60 t 5 12 0)
3593 (64 nil 8 8 0)
3594 (72 nil 9 8 1)
3595 (81 nil 9 9 0)
3596 (90 nil 10 9 1)
3597 (100 nil 10 10 0))
3598 (executive
3599 (1 nil 1 1 0)
3600 (4 nil 2 2 0)
3601 (6 t 2 3 0)
3602 (9 nil 3 3 0)
3603 (12 nil 4 3 1)
3604 (16 nil 4 4 0)
3605 (20 nil 5 4 1)
3606 (25 nil 5 5 0)
3607 (28 t 4 7 0)
3608 (30 nil 6 5 1)
3609 (36 nil 6 6 0)
3610 (42 nil 7 6 1)
3611 (45 t 5 9 0)
3612 (49 nil 7 7 0)
3613 (56 nil 8 7 1)
3614 (60 t 6 10 0)
3615 (64 nil 8 8 0)
3616 (72 nil 9 8 1)
3617 (81 nil 9 9 0)
3618 (84 t 7 12 0)
3619 (90 nil 10 9 1)
3620 (100 nil 10 10 0))
3621 (a4small
3622 (1 nil 1 1 0)
3623 (2 t 1 2 0)
3624 (4 nil 2 2 0)
3625 (6 t 2 3 1)
3626 (8 t 2 4 0)
3627 (9 nil 3 3 0)
3628 (12 nil 4 3 1)
3629 (16 nil 4 4 0)
3630 (18 t 3 6 0)
3631 (20 nil 5 4 1)
3632 (25 nil 5 5 0)
3633 (30 nil 6 5 1)
3634 (32 t 4 8 0)
3635 (36 nil 6 6 0)
3636 (42 nil 7 6 1)
3637 (49 nil 7 7 0)
3638 (50 t 5 10 0)
3639 (56 nil 8 7 1)
3640 (64 nil 8 8 0)
3641 (72 nil 9 8 1)
3642 (78 t 6 13 0)
3643 (81 nil 9 9 0)
3644 (90 nil 10 9 1)
3645 (100 nil 10 10 0))
3646 (b4
3647 (1 nil 1 1 0)
3648 (2 t 1 2 0)
3649 (4 nil 2 2 0)
3650 (6 t 2 3 1)
3651 (8 t 2 4 0)
3652 (9 nil 3 3 0)
3653 (12 nil 4 3 1)
3654 (16 nil 4 4 0)
3655 (18 t 3 6 0)
3656 (20 nil 5 4 1)
3657 (25 nil 5 5 0)
3658 (30 nil 6 5 1)
3659 (32 t 4 8 0)
3660 (36 nil 6 6 0)
3661 (42 nil 7 6 1)
3662 (49 nil 7 7 0)
3663 (50 t 5 10 0)
3664 (56 nil 8 7 1)
3665 (64 nil 8 8 0)
3666 (72 nil 9 8 1)
3667 (81 nil 9 9 0)
3668 (90 nil 10 9 1)
3669 (100 nil 10 10 0))
3670 (b5
3671 (1 nil 1 1 0)
3672 (2 t 1 2 0)
3673 (4 nil 2 2 0)
3674 (6 t 2 3 1)
3675 (8 t 2 4 0)
3676 (9 nil 3 3 0)
3677 (12 nil 4 3 1)
3678 (16 nil 4 4 0)
3679 (18 t 3 6 0)
3680 (20 nil 5 4 1)
3681 (25 nil 5 5 0)
3682 (30 nil 6 5 1)
3683 (32 t 4 8 0)
3684 (36 nil 6 6 0)
3685 (42 nil 7 6 1)
3686 (49 nil 7 7 0)
3687 (50 t 5 10 0)
3688 (56 nil 8 7 1)
3689 (64 nil 8 8 0)
3690 (72 nil 9 8 0)
3691 (81 nil 9 9 0)
3692 (90 nil 10 9 1)
3693 (98 t 7 14 0)
3694 (100 nil 10 10 0)))
3695 "Alist which is the page matrix database used for N-up printing.
3696
3697Each element has the following form:
3698
3699 (PAGE
3700 (MAX LANDSCAPE LINES COLUMNS COL-MISSING)
3701 ...)
3702
3703Where:
3704PAGE is the page size used (see `ps-paper-type').
3705MAX is the maximum elements of this page matrix.
3706LANDSCAPE specifies if page matrix is landscaped, has the following valid
3707 values:
3708 nil the sheet is in portrait mode.
3709 t the sheet is in landscape mode.
3710 pag the sheet is in portrait mode and page is in landscape mode.
3711LINES is the number of lines of page matrix.
3712COLUMNS is the number of columns of page matrix.
3713COL-MISSING is the number of columns missing to fill the sheet.")
3714
3715
3716(defmacro ps-n-up-landscape (mat) `(nth 1 ,mat))
3717(defmacro ps-n-up-lines (mat) `(nth 2 ,mat))
3718(defmacro ps-n-up-columns (mat) `(nth 3 ,mat))
3719(defmacro ps-n-up-missing (mat) `(nth 4 ,mat))
3720
3721
3722(defun ps-n-up-printing ()
3723 ;; force `ps-n-up-printing' be in range 1 to 100.
3724 (setq ps-n-up-printing (max (min ps-n-up-printing 100) 1))
3725 ;; find suitable page matrix for a given `ps-paper-type'.
3726 (let ((the-list (cdr (assq ps-paper-type ps-n-up-database))))
3727 (and the-list
3728 (while (> ps-n-up-printing (caar the-list))
3729 (setq the-list (cdr the-list))))
3730 (car the-list)))
3731
3732
3733(defconst ps-n-up-filling-database
3734 '((left-top
3735 "PageWidth" ; N-Up-XColumn
3736 "0" ; N-Up-YColumn
3737 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3738 "LandscapePageHeight neg" ; N-Up-YLine
3739 "N-Up-Lines" ; N-Up-Repeat
3740 "N-Up-Columns" ; N-Up-End
3741 "0" ; N-Up-XStart
3742 "0") ; N-Up-YStart
3743 (left-bottom
3744 "PageWidth" ; N-Up-XColumn
3745 "0" ; N-Up-YColumn
3746 "N-Up-End 1 sub PageWidth mul neg" ; N-Up-XLine
3747 "LandscapePageHeight" ; N-Up-YLine
3748 "N-Up-Lines" ; N-Up-Repeat
3749 "N-Up-Columns" ; N-Up-End
3750 "0" ; N-Up-XStart
3751 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3752 (right-top
3753 "PageWidth neg" ; N-Up-XColumn
3754 "0" ; N-Up-YColumn
3755 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3756 "LandscapePageHeight neg" ; N-Up-YLine
3757 "N-Up-Lines" ; N-Up-Repeat
3758 "N-Up-Columns" ; N-Up-End
3759 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3760 "0") ; N-Up-YStart
3761 (right-bottom
3762 "PageWidth neg" ; N-Up-XColumn
3763 "0" ; N-Up-YColumn
3764 "N-Up-End 1 sub PageWidth mul" ; N-Up-XLine
3765 "LandscapePageHeight" ; N-Up-YLine
3766 "N-Up-Lines" ; N-Up-Repeat
3767 "N-Up-Columns" ; N-Up-End
3768 "N-Up-End 1 sub PageWidth mul" ; N-Up-XStart
3769 "N-Up-Repeat 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3770 (top-left
3771 "0" ; N-Up-XColumn
3772 "LandscapePageHeight neg" ; N-Up-YColumn
3773 "PageWidth" ; N-Up-XLine
3774 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3775 "N-Up-Columns" ; N-Up-Repeat
3776 "N-Up-Lines" ; N-Up-End
3777 "0" ; N-Up-XStart
3778 "0") ; N-Up-YStart
3779 (bottom-left
3780 "0" ; N-Up-XColumn
3781 "LandscapePageHeight" ; N-Up-YColumn
3782 "PageWidth" ; N-Up-XLine
3783 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3784 "N-Up-Columns" ; N-Up-Repeat
3785 "N-Up-Lines" ; N-Up-End
3786 "0" ; N-Up-XStart
3787 "N-Up-End 1 sub LandscapePageHeight mul neg") ; N-Up-YStart
3788 (top-right
3789 "0" ; N-Up-XColumn
3790 "LandscapePageHeight neg" ; N-Up-YColumn
3791 "PageWidth neg" ; N-Up-XLine
3792 "N-Up-End 1 sub LandscapePageHeight mul" ; N-Up-YLine
3793 "N-Up-Columns" ; N-Up-Repeat
3794 "N-Up-Lines" ; N-Up-End
3795 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3796 "0") ; N-Up-YStart
3797 (bottom-right
3798 "0" ; N-Up-XColumn
3799 "LandscapePageHeight" ; N-Up-YColumn
3800 "PageWidth neg" ; N-Up-XLine
3801 "N-Up-End 1 sub LandscapePageHeight mul neg" ; N-Up-YLine
3802 "N-Up-Columns" ; N-Up-Repeat
3803 "N-Up-Lines" ; N-Up-End
3804 "N-Up-Repeat 1 sub PageWidth mul" ; N-Up-XStart
3805 "N-Up-End 1 sub LandscapePageHeight mul neg")) ; N-Up-YStart
3806 "Alist for n-up printing initializations.
3807
3808Each element has the following form:
3809
3810 (KIND XCOL YCOL XLIN YLIN REPEAT END XSTART YSTART)
3811
3812Where:
3813KIND is a valid value of `ps-n-up-filling'.
3814XCOL YCOL are the relative position for the next column.
3815XLIN YLIN are the relative position for the beginning of next line.
3816REPEAT is the number of repetions for external loop.
3817END is the number of repetions for internal loop and also the number of pages in
3818 a row.
3819XSTART YSTART are the relative position for the first page in a sheet.")
3820
3821
3822(defun ps-n-up-filling ()
3823 (cdr (or (assq ps-n-up-filling ps-n-up-filling-database)
3824 (assq 'left-top ps-n-up-filling-database))))
3825
3826
3827(defmacro ps-n-up-xcolumn (init) `(nth 0 ,init))
3828(defmacro ps-n-up-ycolumn (init) `(nth 1 ,init))
3829(defmacro ps-n-up-xline (init) `(nth 2 ,init))
3830(defmacro ps-n-up-yline (init) `(nth 3 ,init))
3831(defmacro ps-n-up-repeat (init) `(nth 4 ,init))
3832(defmacro ps-n-up-end (init) `(nth 5 ,init))
3833(defmacro ps-n-up-xstart (init) `(nth 6 ,init))
3834(defmacro ps-n-up-ystart (init) `(nth 7 ,init))
3835
3836
66e63857
GM
3837(defconst ps-error-handler-alist
3838 '((none . 0)
3839 (paper . 1)
3840 (system . 2)
3841 (paper-and-system . 3))
3842 "Alist for error handler message")
3843
3844
ef2cbb24 3845(defun ps-begin-file ()
bcc0d457 3846 (ps-get-page-dimensions)
7da17ab6 3847 (setq ps-page-postscript 0
bc0d41bd 3848 ps-page-order 0
87a16a06
RS
3849 ps-background-text-count 0
3850 ps-background-image-count 0
3851 ps-background-pages nil
3852 ps-background-all-pages nil)
12d89a2e 3853
bc0d41bd
KH
3854 (let ((dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
3855 (tumble (if ps-landscape-mode (not ps-spool-tumble) ps-spool-tumble))
3856 (n-up (ps-n-up-printing))
3857 (n-up-filling (ps-n-up-filling)))
3858 (and (> ps-n-up-printing 1) (setq tumble (not tumble)))
3859 (ps-output
3860 ps-adobe-tag
3861 "%%Title: " (buffer-name) ; Take job name from name of
8bd22fcf 3862 ; first buffer printed
bc0d41bd
KH
3863 "\n%%Creator: " (user-full-name)
3864 " (using ps-print v" ps-print-version
3865 ")\n%%CreationDate: "
3866 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy)
3867 "\n%%Orientation: "
3868 (if ps-landscape-mode "Landscape" "Portrait")
3869 "\n%%DocumentNeededResources: font Times-Roman Times-Italic\n%%+ font "
3870 (mapconcat 'identity
3871 (ps-remove-duplicates
3872 (append (ps-fonts 'ps-font-for-text)
3873 (list (ps-font 'ps-font-for-header 'normal)
3874 (ps-font 'ps-font-for-header 'bold))))
3875 "\n%%+ font ")
3876 "\n%%DocumentMedia: " (ps-page-dimensions-get-media dimensions)
3877 (format " %d" (round (ps-page-dimensions-get-width dimensions)))
3878 (format " %d" (round (ps-page-dimensions-get-height dimensions)))
3879 " 0 () ()\n%%PageOrder: Ascend\n%%Pages: (atend)\n%%Requirements:"
3880 (if ps-spool-duplex
3881 (format " duplex%s" (if tumble "(tumble)\n" "\n"))
3882 "\n"))
3883
66e63857 3884 (ps-insert-string ps-print-prologue-header)
bc0d41bd
KH
3885
3886 (ps-output "%%EndComments\n\n%%BeginPrologue\n\n"
6e1b1da6
GM
3887 "/languagelevel where{pop}{/languagelevel 1 def}ifelse\n"
3888 (format "/ErrorMessage %s def\n\n"
66e63857
GM
3889 (or (cdr (assoc ps-error-handler-message
3890 ps-error-handler-alist))
3891 1)) ; send to paper
3892 ps-print-prologue-0
3893 "\n%%BeginProcSet: UserDefinedPrologue\n\n")
3894
3895 (ps-insert-string ps-user-defined-prologue)
3896
3897 (ps-output "\n%%EndProcSet\n\n")
bc0d41bd 3898
bc0d41bd
KH
3899 (ps-output-boolean "LandscapeMode "
3900 (or ps-landscape-mode
3901 (eq (ps-n-up-landscape n-up) 'pag)))
906d41a7 3902 (ps-output-boolean "UpsideDown " ps-print-upside-down)
bc0d41bd
KH
3903 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns)
3904
3905 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height)
3906 (format "/PrintPageWidth %s def\n"
3907 (- (* (+ ps-print-width ps-inter-column)
3908 ps-number-of-columns)
3909 ps-inter-column))
3910 (format "/PrintWidth %s def\n" ps-print-width)
3911 (format "/PrintHeight %s def\n" ps-print-height)
3912
3913 (format "/LeftMargin %s def\n" ps-left-margin)
3914 (format "/RightMargin %s def\n" ps-right-margin)
3915 (format "/InterColumn %s def\n" ps-inter-column)
3916
3917 (format "/BottomMargin %s def\n" ps-bottom-margin)
3918 (format "/TopMargin %s def\n" ps-top-margin) ; not used
3919 (format "/HeaderOffset %s def\n" ps-header-offset)
3920 (format "/HeaderPad %s def\n" ps-header-pad))
3921
3922 (ps-output-boolean "PrintHeader " ps-print-header)
3923 (ps-output-boolean "PrintOnlyOneHeader" ps-print-only-one-header)
3924 (ps-output-boolean "PrintHeaderFrame " ps-print-header-frame)
3925 (ps-output-boolean "ShowNofN " ps-show-n-of-n)
3926 (ps-output-boolean "DuplexValue " ps-spool-duplex)
3927 (ps-output-boolean "TumbleValue " tumble)
3928
3929 (let ((line-height (ps-line-height 'ps-font-for-text)))
3930 (ps-output (format "/LineHeight %s def\n" line-height)
3931 (format "/LinesPerColumn %d def\n"
3932 (round (/ (+ ps-print-height
3933 (* line-height 0.45))
3934 line-height)))))
3935
3936 (ps-output-boolean "Zebra " ps-zebra-stripes)
3937 (ps-output-boolean "PrintLineNumber " ps-line-number)
906d41a7
GM
3938 (ps-output-boolean "SyncLineZebra " (not (integerp ps-line-number-step)))
3939 (ps-output (format "/PrintLineStep %d def\n"
3940 (if (integerp ps-line-number-step)
3941 ps-line-number-step
3942 1))
3943 (format "/ZebraHeight %d def\n" ps-zebra-stripe-height)
6e1b1da6
GM
3944 "/ZebraColor "
3945 (ps-format-color ps-zebra-color 0.95)
3946 "def\n/BackgroundColor "
3947 (ps-format-color ps-default-bg 1.0)
3948 "def\n/UseSetpagedevice "
bc0d41bd 3949 (if (eq ps-spool-config 'setpagedevice)
6e1b1da6
GM
3950 "/setpagedevice where{pop languagelevel 2 eq}{false}ifelse"
3951 "false")
3952 " def\n\n/PageWidth "
bc0d41bd
KH
3953 "PrintPageWidth LeftMargin add RightMargin add def\n\n"
3954 (format "/N-Up %d def\n" ps-n-up-printing))
3955 (ps-output-boolean "N-Up-Landscape" (eq (ps-n-up-landscape n-up) t))
3956 (ps-output-boolean "N-Up-Border " ps-n-up-border-p)
3957 (ps-output (format "/N-Up-Lines %d def\n" (ps-n-up-lines n-up))
3958 (format "/N-Up-Columns %d def\n" (ps-n-up-columns n-up))
3959 (format "/N-Up-Missing %d def\n" (ps-n-up-missing n-up))
6e1b1da6
GM
3960 (format "/N-Up-Margin %s def\n" ps-n-up-margin)
3961 "/N-Up-Repeat "
bc0d41bd
KH
3962 (if ps-landscape-mode
3963 (ps-n-up-end n-up-filling)
3964 (ps-n-up-repeat n-up-filling))
3965 " def\n/N-Up-End "
3966 (if ps-landscape-mode
3967 (ps-n-up-repeat n-up-filling)
3968 (ps-n-up-end n-up-filling))
3969 " def\n/N-Up-XColumn " (ps-n-up-xcolumn n-up-filling)
3970 " def\n/N-Up-YColumn " (ps-n-up-ycolumn n-up-filling)
3971 " def\n/N-Up-XLine " (ps-n-up-xline n-up-filling)
3972 " def\n/N-Up-YLine " (ps-n-up-yline n-up-filling)
3973 " def\n/N-Up-XStart " (ps-n-up-xstart n-up-filling)
3974 " def\n/N-Up-YStart " (ps-n-up-ystart n-up-filling) " def\n")
3975
3976 (ps-background-text)
3977 (ps-background-image)
3978 (setq ps-background-all-pages (nreverse ps-background-all-pages)
3979 ps-background-pages (nreverse ps-background-pages))
3980
41481e4b 3981 (ps-output "\n" ps-print-prologue-1)
bc0d41bd 3982
41481e4b 3983 (ps-output "\n/printGlobalBackground {\n")
bc0d41bd
KH
3984 (ps-output-list ps-background-all-pages)
3985 (ps-output "} def\n/printLocalBackground {\n} def\n")
3986
3987 ;; Header fonts
3988 (ps-output (format "/h0 %s (%s) cvn DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
3989 ps-header-title-font-size-internal
3990 (ps-font 'ps-font-for-header 'bold))
3991 (format "/h1 %s (%s) cvn DefFont\n" ; /h1 12 /Helvetica DefFont
3992 ps-header-font-size-internal
3993 (ps-font 'ps-font-for-header 'normal)))
3994
41481e4b 3995 (ps-output "\n" ps-print-prologue-2 "\n")
bc0d41bd
KH
3996
3997 ;; Text fonts
3998 (let ((font (ps-font-alist 'ps-font-for-text))
3999 (i 0))
4000 (while font
4001 (ps-output (format "/f%d %s (%s) cvn DefFont\n"
4002 i
4003 ps-font-size-internal
4004 (ps-font 'ps-font-for-text (car (car font)))))
4005 (setq font (cdr font)
4006 i (1+ i))))
4007
4008 (let ((font-entry (cdr (assq ps-font-family ps-font-info-database))))
4009 (ps-output (format "/SpaceWidthRatio %f def\n"
4010 (/ (ps-lookup 'space-width) (ps-lookup 'size)))))
4011
4012 (ps-output "\n%%EndPrologue\n\n%%BeginSetup\n")
4013 (unless (eq ps-spool-config 'lpr-switches)
4014 (ps-output "\n%%BeginFeature: *Duplex "
4015 (ps-boolean-capitalized ps-spool-duplex)
4016 " *Tumble "
4017 (ps-boolean-capitalized tumble)
41481e4b 4018 "\n\n"
bc0d41bd 4019 ps-print-duplex-feature
41481e4b 4020 "\n%%EndFeature\n")))
47d2ac75
GM
4021 (ps-output "\n/Lines 0 def\n/PageCount 0 def\n\nBeginDoc\n%%EndSetup\n")
4022 (and ps-banner-page-when-duplexing
4023 (ps-output "\n%%Page: 0 0\nsave showpage restore\n")))
bc0d41bd
KH
4024
4025
6e1b1da6
GM
4026(defun ps-format-color (color &optional default)
4027 (let ((the-color (if (stringp color)
4028 (ps-color-scale color)
4029 color)))
4030 (if (and the-color (listp the-color))
4031 (concat "["
4032 (format ps-color-format
4033 (nth 0 the-color)
4034 (nth 1 the-color)
4035 (nth 2 the-color))
4036 "] ")
4037 (ps-float-format (if (numberp the-color) the-color default)))))
4038
4039
66e63857
GM
4040(defun ps-insert-string (prologue)
4041 (let ((str (if (functionp prologue)
4042 (funcall prologue)
4043 prologue)))
4044 (and (stringp str)
4045 (ps-output str))))
4046
4047
bc0d41bd
KH
4048(defun ps-boolean-capitalized (bool)
4049 (if bool "True" "False"))
4050
ef2cbb24 4051
12d89a2e
RS
4052(defun ps-header-dirpart ()
4053 (let ((fname (buffer-file-name)))
4054 (if fname
4055 (if (string-equal (buffer-name) (file-name-nondirectory fname))
68e684a0 4056 (abbreviate-file-name (file-name-directory fname))
12d89a2e
RS
4057 fname)
4058 "")))
ef2cbb24 4059
bc0d41bd 4060
12d89a2e 4061(defun ps-get-buffer-name ()
bcc0d457
RS
4062 (cond
4063 ;; Indulge Jim this little easter egg:
4064 ((string= (buffer-name) "ps-print.el")
4065 "Hey, Cool! It's ps-print.el!!!")
4066 ;; Indulge Jack this other little easter egg:
4067 ((string= (buffer-name) "sokoban.el")
4068 "Super! C'est sokoban.el!")
87a16a06 4069 (t (concat
bc0d41bd 4070 (and ps-printing-region-p "Subset of: ")
87a16a06
RS
4071 (buffer-name)
4072 (and (buffer-modified-p) " (unsaved)")))))
ef2cbb24 4073
7d8b7e8e
KH
4074
4075(defun ps-get-font-size (font-sym)
4076 (let ((font-size (symbol-value font-sym)))
4077 (cond ((numberp font-size)
4078 font-size)
4079 ((and (consp font-size)
4080 (numberp (car font-size))
4081 (numberp (cdr font-size)))
4082 (if ps-landscape-mode
4083 (car font-size)
4084 (cdr font-size)))
4085 (t
4086 (error "Invalid font size `%S' for `%S'" font-size font-sym)))))
4087
4088
12d89a2e 4089(defun ps-begin-job ()
906d41a7
GM
4090 (let ((last-char (aref ps-postscript-code-directory
4091 (1- (length ps-postscript-code-directory)))))
4092 (or (eq last-char ?/)
4093 (and ps-windows-system (eq last-char ?\\))
4094 (setq ps-postscript-code-directory
4095 (concat ps-postscript-code-directory "/"))))
41481e4b 4096 (or (equal ps-mark-code-directory ps-postscript-code-directory)
66e63857
GM
4097 (setq ps-print-prologue-0 (ps-prologue-file 0)
4098 ps-print-prologue-1 (ps-prologue-file 1)
41481e4b
KH
4099 ps-print-prologue-2 (ps-prologue-file 2)
4100 ps-print-duplex-feature (ps-prologue-file 3)
4101 ps-mark-code-directory ps-postscript-code-directory))
906d41a7
GM
4102 (or (listp ps-use-face-background)
4103 (setq ps-use-face-background t))
4104 (and (integerp ps-line-number-step)
4105 (<= ps-line-number-step 0)
4106 (setq ps-line-number-step 1))
7da17ab6
RS
4107 (save-excursion
4108 (set-buffer ps-spool-buffer)
4109 (goto-char (point-max))
4110 (and (re-search-backward "^%%Trailer$" nil t)
4111 (delete-region (match-beginning 0) (point-max))))
bc0d41bd 4112 (setq ps-showline-count (car ps-printing-region)
7da17ab6 4113 ps-page-count 0
7d8b7e8e
KH
4114 ps-font-size-internal (ps-get-font-size 'ps-font-size)
4115 ps-header-font-size-internal (ps-get-font-size 'ps-header-font-size)
4116 ps-header-title-font-size-internal
4117 (ps-get-font-size 'ps-header-title-font-size)
857686a6 4118 ps-control-or-escape-regexp
298bfad9
KH
4119 (cond ((eq ps-print-control-characters '8-bit)
4120 (string-as-unibyte "[\000-\037\177-\377]"))
4121 ((eq ps-print-control-characters 'control-8-bit)
4122 (string-as-unibyte "[\000-\037\177-\237]"))
4123 ((eq ps-print-control-characters 'control)
4124 "[\000-\037\177]")
6e1b1da6
GM
4125 (t "[\t\n\f]"))
4126 ps-default-foreground (ps-rgb-color ps-default-fg 0.0)
4127 ps-default-color (and ps-print-color-p ps-default-foreground)
4128 ps-current-color ps-default-color
4129 ;; Set the color scale. We do it here instead of in the defvar so
4130 ;; that ps-print can be dumped into emacs. This expression can't be
4131 ;; evaluated at dump-time because X isn't initialized.
4132 ps-color-p (and ps-print-color-p (ps-color-device))
4133 ps-print-color-scale (if ps-color-p
4134 (float (car (ps-color-values "white")))
4135 1.0)))
4136
4137
4138(defun ps-rgb-color (color default)
4139 (cond ((and color (listp color)) color)
4140 ((stringp color) (ps-color-scale color))
4141 ((numberp color) (list color color color))
4142 (t (list default default default))
4143 ))
4144
ef2cbb24 4145
12b88fff
RS
4146(defmacro ps-page-number ()
4147 `(1+ (/ (1- ps-page-count) ps-number-of-columns)))
4148
47d2ac75 4149(defun ps-end-file (needs-begin-file)
133fc764 4150 (ps-flush-output)
bc0d41bd
KH
4151 ;; Back to the PS output buffer to set the last page n-up printing
4152 (save-excursion
4153 (let ((pages-per-sheet (mod ps-page-postscript ps-n-up-printing))
4154 case-fold-search)
4155 (set-buffer ps-spool-buffer)
4156 (goto-char (point-max))
4157 (and (> pages-per-sheet 0)
4158 (re-search-backward "^[0-9]+ BeginSheet$" nil t)
4159 (replace-match (format "%d BeginSheet" pages-per-sheet) t))))
4160 ;; Set dummy page
4161 (and ps-spool-duplex (= (mod ps-page-order 2) 1)
4162 (ps-dummy-page))
4163 ;; Set end of PostScript file
4164 (ps-output "EndSheet\n\n%%Trailer\n%%Pages: "
47d2ac75
GM
4165 (format "%d"
4166 (if (and needs-begin-file ps-banner-page-when-duplexing)
4167 (1+ ps-page-order)
4168 ps-page-order))
984e7bd9 4169 "\n\nEndDoc\n\n%%EOF\n"))
87a16a06
RS
4170
4171
ef2cbb24
RS
4172(defun ps-next-page ()
4173 (ps-end-page)
12d89a2e
RS
4174 (ps-flush-output)
4175 (ps-begin-page))
4176
bc0d41bd
KH
4177
4178(defun ps-header-sheet ()
4179 ;; Print only when a new sheet begins.
4180 (setq ps-page-postscript (1+ ps-page-postscript)
4181 ps-page-order (1+ ps-page-order))
4182 (and (> ps-page-order 1)
4183 (ps-output "EndSheet\n"))
4184 (ps-output (format "\n%%%%Page: %d %d\n"
4185 ps-page-postscript ps-page-order))
4186 (ps-output (format "%d BeginSheet\nBeginDSCPage\n" ps-n-up-printing)))
4187
4188
4189(defsubst ps-header-page ()
7da17ab6
RS
4190 ;; set total line and page number when printing has finished
4191 ;; (see `ps-generate')
bc0d41bd
KH
4192 (run-hooks
4193 (if (prog1
4194 (zerop (mod ps-page-count ps-number-of-columns))
4195 (setq ps-page-count (1+ ps-page-count)))
4196 (prog1
4197 (if (zerop (mod ps-page-postscript ps-n-up-printing))
4198 ;; Print only when a new sheet begins.
4199 (progn
4200 (ps-header-sheet)
4201 'ps-print-begin-sheet-hook)
4202 ;; Print only when a new page begins.
4203 (setq ps-page-postscript (1+ ps-page-postscript))
4204 (ps-output "BeginDSCPage\n")
4205 'ps-print-begin-page-hook)
4206 (ps-background ps-page-postscript))
4207 ;; Print only when a new column begins.
4208 (ps-output "BeginDSCPage\n")
4209 'ps-print-begin-column-hook)))
a18ed129 4210
8bd22fcf 4211(defun ps-begin-page ()
12d89a2e 4212 (ps-get-page-dimensions)
8bd22fcf 4213 (setq ps-width-remaining ps-print-width
298bfad9 4214 ps-height-remaining ps-print-height)
12d89a2e 4215
a18ed129 4216 (ps-header-page)
12d89a2e 4217
87a16a06 4218 (ps-output (format "/LineNumber %d def\n" ps-showline-count)
12b88fff
RS
4219 (format "/PageNumber %d def\n" (if ps-print-only-one-header
4220 (ps-page-number)
4221 ps-page-count)))
12d89a2e 4222
090be653
RS
4223 (when ps-print-header
4224 (ps-generate-header "HeaderLinesLeft" ps-left-header)
4225 (ps-generate-header "HeaderLinesRight" ps-right-header)
4226 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
12d89a2e
RS
4227
4228 (ps-output "BeginPage\n")
87a16a06
RS
4229 (ps-set-font ps-current-font)
4230 (ps-set-bg ps-current-bg)
298bfad9
KH
4231 (ps-set-color ps-current-color)
4232 (ps-mule-begin-page))
ef2cbb24
RS
4233
4234(defun ps-end-page ()
a18ed129 4235 (ps-output "EndPage\nEndDSCPage\n"))
12d89a2e
RS
4236
4237(defun ps-dummy-page ()
bc0d41bd
KH
4238 (let ((ps-n-up-printing 0))
4239 (ps-header-sheet))
a18ed129 4240 (ps-output "/PrintHeader false def
bc0d41bd
KH
4241/ColumnIndex 0 def
4242/PrintLineNumber false def
12d89a2e
RS
4243BeginPage
4244EndPage
bc0d41bd
KH
4245EndDSCPage\n")
4246 (setq ps-page-postscript ps-n-up-printing))
06fb6aab 4247
ef2cbb24 4248(defun ps-next-line ()
87a16a06 4249 (setq ps-showline-count (1+ ps-showline-count))
12b88fff
RS
4250 (let ((lh (ps-line-height 'ps-font-for-text)))
4251 (if (< ps-height-remaining lh)
4252 (ps-next-page)
4253 (setq ps-width-remaining ps-print-width
4254 ps-height-remaining (- ps-height-remaining lh))
4255 (ps-output "HL\n"))))
ef2cbb24
RS
4256
4257(defun ps-continue-line ()
12b88fff
RS
4258 (let ((lh (ps-line-height 'ps-font-for-text)))
4259 (if (< ps-height-remaining lh)
4260 (ps-next-page)
4261 (setq ps-width-remaining ps-print-width
4262 ps-height-remaining (- ps-height-remaining lh))
4263 (ps-output "SL\n"))))
12d89a2e
RS
4264
4265(defun ps-find-wrappoint (from to char-width)
4266 (let ((avail (truncate (/ ps-width-remaining char-width)))
4267 (todo (- to from)))
4268 (if (< todo avail)
4269 (cons to (* todo char-width))
4270 (cons (+ from avail) ps-width-remaining))))
4271
4272(defun ps-basic-plot-string (from to &optional bg-color)
12b88fff
RS
4273 (let* ((wrappoint (ps-find-wrappoint from to
4274 (ps-avg-char-width 'ps-font-for-text)))
12d89a2e 4275 (to (car wrappoint))
298bfad9
KH
4276 (string (buffer-substring-no-properties from to)))
4277 (ps-mule-prepare-ascii-font string)
12d89a2e 4278 (ps-output-string string)
bcc0d457 4279 (ps-output " S\n")
12d89a2e
RS
4280 wrappoint))
4281
4282(defun ps-basic-plot-whitespace (from to &optional bg-color)
12b88fff
RS
4283 (let* ((wrappoint (ps-find-wrappoint from to
4284 (ps-space-width 'ps-font-for-text)))
12d89a2e 4285 (to (car wrappoint)))
12d89a2e
RS
4286 (ps-output (format "%d W\n" (- to from)))
4287 wrappoint))
4288
4289(defun ps-plot (plotfunc from to &optional bg-color)
ef2cbb24 4290 (while (< from to)
12d89a2e
RS
4291 (let* ((wrappoint (funcall plotfunc from to bg-color))
4292 (plotted-to (car wrappoint))
4293 (plotted-width (cdr wrappoint)))
8bd22fcf
KH
4294 (setq from plotted-to
4295 ps-width-remaining (- ps-width-remaining plotted-width))
12d89a2e
RS
4296 (if (< from to)
4297 (ps-continue-line))))
ef2cbb24
RS
4298 (if ps-razzle-dazzle
4299 (let* ((q-todo (- (point-max) (point-min)))
12d89a2e 4300 (q-done (- (point) (point-min)))
ef2cbb24 4301 (chunkfrac (/ q-todo 8))
857686a6 4302 (chunksize (min chunkfrac 1000)))
ef2cbb24 4303 (if (> (- q-done ps-razchunk) chunksize)
8bd22fcf 4304 (progn
ef2cbb24 4305 (setq ps-razchunk q-done)
8bd22fcf
KH
4306 (message "Formatting...%3d%%"
4307 (if (< q-todo 100)
4308 (/ (* 100 q-done) q-todo)
4309 (/ q-done (/ q-todo 100)))
4310 ))))))
12d89a2e 4311
298bfad9
KH
4312(defvar ps-last-font nil)
4313
12d89a2e 4314(defun ps-set-font (font)
e65df0a1
KH
4315 (setq ps-last-font (format "f%d" (setq ps-current-font font)))
4316 (ps-output (format "/%s F\n" ps-last-font)))
12d89a2e 4317
12d89a2e
RS
4318(defun ps-set-bg (color)
4319 (if (setq ps-current-bg color)
8bd22fcf
KH
4320 (ps-output (format ps-color-format
4321 (nth 0 color) (nth 1 color) (nth 2 color))
12d89a2e
RS
4322 " true BG\n")
4323 (ps-output "false BG\n")))
4324
4325(defun ps-set-color (color)
6e1b1da6 4326 (setq ps-current-color (or color ps-default-foreground))
8bd22fcf
KH
4327 (ps-output (format ps-color-format
4328 (nth 0 ps-current-color)
043620f4
KH
4329 (nth 1 ps-current-color) (nth 2 ps-current-color))
4330 " FG\n"))
12d89a2e 4331
12d89a2e 4332
87a16a06 4333(defvar ps-current-effect 0)
12d89a2e 4334
87a16a06
RS
4335
4336(defun ps-plot-region (from to font &optional fg-color bg-color effects)
12d89a2e
RS
4337 (if (not (equal font ps-current-font))
4338 (ps-set-font font))
06fb6aab 4339
12d89a2e
RS
4340 ;; Specify a foreground color only if one's specified and it's
4341 ;; different than the current.
4342 (if (not (equal fg-color ps-current-color))
4343 (ps-set-color fg-color))
06fb6aab 4344
12d89a2e
RS
4345 (if (not (equal bg-color ps-current-bg))
4346 (ps-set-bg bg-color))
06fb6aab 4347
87a16a06
RS
4348 ;; Specify effects (underline, overline, box, etc)
4349 (cond
4350 ((not (integerp effects))
4351 (ps-output "0 EF\n")
4352 (setq ps-current-effect 0))
4353 ((/= effects ps-current-effect)
4354 (ps-output (number-to-string effects) " EF\n")
4355 (setq ps-current-effect effects)))
ef2cbb24 4356
12d89a2e 4357 ;; Starting at the beginning of the specified region...
ef2cbb24
RS
4358 (save-excursion
4359 (goto-char from)
12d89a2e
RS
4360
4361 ;; ...break the region up into chunks separated by tabs, linefeeds,
87a16a06 4362 ;; pagefeeds, control characters, and plot each chunk.
ef2cbb24 4363 (while (< from to)
857686a6 4364 (if (re-search-forward ps-control-or-escape-regexp to t)
024ced4d 4365 ;; region with some control characters or some multi-byte characters
12b88fff 4366 (let* ((match-point (match-beginning 0))
9d4d60c1
KH
4367 (match (char-after match-point))
4368 (composition (find-composition from (1+ match-point))))
4369 (if composition
4370 (if (and (nth 2 composition)
4371 (<= (car composition) match-point))
4372 (progn
4373 (setq match-point (car composition)
4374 match 0)
4375 (goto-char (nth 1 composition)))
4376 (setq composition nil)))
e65df0a1 4377 (when (< from match-point)
298bfad9 4378 (ps-mule-set-ascii-font)
e65df0a1 4379 (ps-plot 'ps-basic-plot-string from match-point bg-color))
857686a6
RS
4380 (cond
4381 ((= match ?\t) ; tab
be415ea7 4382 (let ((linestart (line-beginning-position)))
857686a6
RS
4383 (forward-char -1)
4384 (setq from (+ linestart (current-column)))
e65df0a1 4385 (when (re-search-forward "[ \t]+" to t)
298bfad9 4386 (ps-mule-set-ascii-font)
e65df0a1
KH
4387 (ps-plot 'ps-basic-plot-whitespace
4388 from (+ linestart (current-column))
4389 bg-color))))
857686a6
RS
4390
4391 ((= match ?\n) ; newline
4392 (ps-next-line))
4393
4394 ((= match ?\f) ; form feed
12b88fff
RS
4395 ;; do not skip page if previous character is NEWLINE and
4396 ;; it is a beginning of page.
4397 (or (and (= (char-after (1- match-point)) ?\n)
4398 (= ps-height-remaining ps-print-height))
4399 (ps-next-page)))
e65df0a1 4400
9d4d60c1
KH
4401 (composition ; a composite sequence
4402 (ps-plot 'ps-mule-plot-composition match-point (point) bg-color))
4403
4404 ; characters from ^@ to ^_ and
024ced4d 4405 ((> match 255) ; a multi-byte character
9d4d60c1
KH
4406 (let* ((charset (char-charset match))
4407 (composition (find-composition match-point to))
4408 (stop (if (nth 2 composition) (car composition) to)))
e65df0a1 4409 (or (eq charset 'composition)
9d4d60c1 4410 (while (and (< (point) stop) (eq (charset-after) charset))
298bfad9 4411 (forward-char 1)))
e65df0a1 4412 (ps-plot 'ps-mule-plot-string match-point (point) bg-color)))
9d4d60c1 4413
857686a6
RS
4414 (t ; characters from 127 to 255
4415 (ps-control-character match)))
87a16a06 4416 (setq from (point)))
024ced4d 4417 ;; region without control characters nor multi-byte characters
298bfad9 4418 (ps-mule-set-ascii-font)
87a16a06
RS
4419 (ps-plot 'ps-basic-plot-string from to bg-color)
4420 (setq from to)))))
4421
857686a6
RS
4422(defvar ps-string-control-codes
4423 (let ((table (make-vector 256 nil))
4424 (char ?\000))
4425 ;; control character
4426 (while (<= char ?\037)
4427 (aset table char (format "^%c" (+ char ?@)))
4428 (setq char (1+ char)))
4429 ;; printable character
4430 (while (< char ?\177)
4431 (aset table char (format "%c" char))
4432 (setq char (1+ char)))
4433 ;; DEL
4434 (aset table char "^?")
4435 ;; 8-bit character
4436 (while (<= (setq char (1+ char)) ?\377)
4437 (aset table char (format "\\%o" char)))
4438 table)
4439 "Vector used to map characters to a printable string.")
4440
4441(defun ps-control-character (char)
4442 (let* ((str (aref ps-string-control-codes char))
4443 (from (1- (point)))
87a16a06
RS
4444 (len (length str))
4445 (to (+ from len))
12b88fff
RS
4446 (char-width (ps-avg-char-width 'ps-font-for-text))
4447 (wrappoint (ps-find-wrappoint from to char-width)))
87a16a06
RS
4448 (if (< (car wrappoint) to)
4449 (ps-continue-line))
12b88fff 4450 (setq ps-width-remaining (- ps-width-remaining (* len char-width)))
36243805 4451 (ps-mule-prepare-ascii-font str)
87a16a06
RS
4452 (ps-output-string str)
4453 (ps-output " S\n")))
ef2cbb24 4454
6e1b1da6 4455(defun ps-color-scale (color)
12d89a2e 4456 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
6e1b1da6
GM
4457 (mapcar #'(lambda (value) (/ value ps-print-color-scale))
4458 (ps-color-values color)))
ef2cbb24 4459
d3ab8dac
KH
4460
4461(cond ((eq ps-print-emacs-type 'emacs) ; emacs
4462
4463 (defun ps-color-values (x-color)
4464 (if (fboundp 'x-color-values)
4465 (x-color-values x-color)
4466 (error "No available function to determine X color values.")))
4467 )
4468 ; xemacs
4469 ; lucid
4470 (t ; epoch
4471 (defun ps-color-values (x-color)
6e1b1da6
GM
4472 (let ((the-color (if (color-specifier-p x-color)
4473 (color-name x-color)
4474 x-color)))
4475 (cond
4476 ((fboundp 'x-color-values)
4477 (x-color-values the-color))
4478 ((and (fboundp 'color-instance-rgb-components)
4479 (ps-color-device))
4480 (color-instance-rgb-components
4481 (if (color-instance-p x-color)
4482 x-color
4483 (make-color-instance the-color))))
4484 (t
4485 (error "No available function to determine X color values.")))))
d3ab8dac 4486 ))
043620f4 4487
87a16a06 4488
a18ed129
RS
4489(defun ps-face-attributes (face)
4490 "Return face attribute vector.
87a16a06 4491
a18ed129
RS
4492If FACE is not in `ps-print-face-extension-alist' or in
4493`ps-print-face-alist', insert it on `ps-print-face-alist' and
4494return the attribute vector.
87a16a06
RS
4495
4496If FACE is not a valid face name, it is used default face."
a18ed129
RS
4497 (cdr (or (assq face ps-print-face-extension-alist)
4498 (assq face ps-print-face-alist)
4499 (let* ((the-face (if (facep face) face 'default))
4500 (new-face (ps-screen-to-bit-face the-face)))
4501 (or (and (eq the-face 'default)
4502 (assq the-face ps-print-face-alist))
4503 (setq ps-print-face-alist (cons new-face ps-print-face-alist)))
4504 new-face))))
87a16a06 4505
043620f4 4506
906d41a7
GM
4507(defun ps-face-background (face background)
4508 (and (or (eq ps-use-face-background t)
4509 (cond ((symbolp face)
4510 (memq face ps-use-face-background))
4511 ((listp face)
4512 (let (ok)
4513 (while face
4514 (if (memq (car face) ps-use-face-background)
4515 (setq face nil
4516 ok t)
4517 (setq face (cdr face))))
4518 ok))
4519 (t
4520 nil)
4521 ))
4522 background))
4523
4524
043620f4
KH
4525(defun ps-face-attribute-list (face-or-list)
4526 (if (listp face-or-list)
87a16a06 4527 ;; list of faces
857686a6 4528 (let ((effects 0)
906d41a7 4529 foreground background face-attr face)
043620f4 4530 (while face-or-list
906d41a7
GM
4531 (setq face (car face-or-list)
4532 face-or-list (cdr face-or-list)
4533 face-attr (ps-face-attributes face)
4534 effects (logior effects (aref face-attr 0)))
87a16a06 4535 (or foreground (setq foreground (aref face-attr 1)))
906d41a7
GM
4536 (or background
4537 (setq background (ps-face-background face (aref face-attr 2)))))
87a16a06
RS
4538 (vector effects foreground background))
4539 ;; simple face
043620f4
KH
4540 (ps-face-attributes face-or-list)))
4541
87a16a06 4542
12b88fff
RS
4543(defconst ps-font-type (vector nil 'bold 'italic 'bold-italic))
4544
4545
12d89a2e 4546(defun ps-plot-with-face (from to face)
12b88fff
RS
4547 (cond
4548 ((null face) ; print text with null face
87a16a06 4549 (ps-plot-region from to 0))
12b88fff
RS
4550 ((eq face 'emacs--invisible--face)) ; skip invisible text!!!
4551 (t ; otherwise, text has a valid face
4552 (let* ((face-bit (ps-face-attribute-list face))
4553 (effect (aref face-bit 0))
4554 (foreground (aref face-bit 1))
906d41a7 4555 (background (ps-face-background face (aref face-bit 2)))
d3ab8dac 4556 (fg-color (if (and ps-color-p foreground)
6e1b1da6 4557 (ps-color-scale foreground)
12b88fff 4558 ps-default-color))
d3ab8dac 4559 (bg-color (and ps-color-p background
6e1b1da6 4560 (ps-color-scale background))))
12b88fff
RS
4561 (ps-plot-region
4562 from to
4563 (ps-font-number 'ps-font-for-text
4564 (or (aref ps-font-type (logand effect 3))
4565 face))
4566 fg-color bg-color (lsh effect -2)))))
87a16a06 4567 (goto-char to))
12d89a2e
RS
4568
4569
298bfad9
KH
4570(defun ps-xemacs-face-kind-p (face kind kind-regex kind-list)
4571 (let* ((frame-font (or (face-font-instance face)
4572 (face-font-instance 'default)))
4573 (kind-cons (and frame-font
4574 (assq kind
4575 (font-instance-properties frame-font))))
4576 (kind-spec (cdr-safe kind-cons))
4577 (case-fold-search t))
4578 (or (and kind-spec (string-match kind-regex kind-spec))
4579 ;; Kludge-compatible:
4580 (memq face kind-list))))
4581
4582
e65df0a1
KH
4583(cond ((eq ps-print-emacs-type 'emacs) ; emacs
4584
4585 (defun ps-face-bold-p (face)
4586 (or (face-bold-p face)
4587 (memq face ps-bold-faces)))
4588
4589 (defun ps-face-italic-p (face)
4590 (or (face-italic-p face)
4591 (memq face ps-italic-faces)))
4592 )
4593 ; xemacs
4594 ; lucid
e65df0a1
KH
4595 (t ; epoch
4596 (defun ps-face-bold-p (face)
d3ab8dac
KH
4597 (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold"
4598 ps-bold-faces))
e65df0a1
KH
4599
4600 (defun ps-face-italic-p (face)
4601 (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces)
4602 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces)))
4603 ))
4604
12d89a2e
RS
4605
4606(defun ps-face-underlined-p (face)
4607 (or (face-underline-p face)
4608 (memq face ps-underlined-faces)))
4609
a18ed129 4610
043620f4
KH
4611;; Ensure that face-list is fbound.
4612(or (fboundp 'face-list) (defalias 'face-list 'list-faces))
12d89a2e 4613
a18ed129 4614
12d89a2e 4615(defun ps-build-reference-face-lists ()
857686a6
RS
4616 ;; Ensure that face database is updated with faces on
4617 ;; `font-lock-face-attributes' (obsolete stuff)
4618 (ps-font-lock-face-attributes)
4619 ;; Now, rebuild reference face lists
a18ed129 4620 (setq ps-print-face-alist nil)
12d89a2e 4621 (if ps-auto-font-detect
a18ed129
RS
4622 (mapcar 'ps-map-face (face-list))
4623 (mapcar 'ps-set-face-bold ps-bold-faces)
4624 (mapcar 'ps-set-face-italic ps-italic-faces)
4625 (mapcar 'ps-set-face-underline ps-underlined-faces))
12d89a2e 4626 (setq ps-build-face-reference nil))
ef2cbb24 4627
a18ed129
RS
4628
4629(defun ps-set-face-bold (face)
4630 (ps-set-face-attribute face 1))
4631
4632(defun ps-set-face-italic (face)
4633 (ps-set-face-attribute face 2))
4634
4635(defun ps-set-face-underline (face)
4636 (ps-set-face-attribute face 4))
4637
4638
4639(defun ps-set-face-attribute (face effect)
4640 (let ((face-bit (cdr (ps-map-face face))))
4641 (aset face-bit 0 (logior (aref face-bit 0) effect))))
4642
4643
4644(defun ps-map-face (face)
4645 (let* ((face-map (ps-screen-to-bit-face face))
4646 (ps-face-bit (cdr (assq (car face-map) ps-print-face-alist))))
4647 (if ps-face-bit
4648 ;; if face exists, merge both
4649 (let ((face-bit (cdr face-map)))
4650 (aset ps-face-bit 0 (logior (aref ps-face-bit 0) (aref face-bit 0)))
4651 (or (aref ps-face-bit 1) (aset ps-face-bit 1 (aref face-bit 1)))
4652 (or (aref ps-face-bit 2) (aset ps-face-bit 2 (aref face-bit 2))))
4653 ;; if face does not exist, insert it
4654 (setq ps-print-face-alist (cons face-map ps-print-face-alist)))
4655 face-map))
4656
4657
4658(defun ps-screen-to-bit-face (face)
4659 (cons face
4660 (vector (logior (if (ps-face-bold-p face) 1 0) ; bold
4661 (if (ps-face-italic-p face) 2 0) ; italic
4662 (if (ps-face-underlined-p face) 4 0)) ; underline
4663 (face-foreground face)
4664 (face-background face))))
4665
4666
d3ab8dac
KH
4667(cond ((not (eq ps-print-emacs-type 'emacs))
4668 ; xemacs
4669 ; lucid
4670 ; epoch
4671 (defun ps-mapper (extent list)
4672 (nconc list (list (list (extent-start-position extent) 'push extent)
4673 (list (extent-end-position extent) 'pull extent)))
4674 nil)
4675
4676 (defun ps-extent-sorter (a b)
4677 (< (extent-priority a) (extent-priority b)))
4678 ))
ef2cbb24 4679
043620f4
KH
4680
4681(defun ps-print-ensure-fontified (start end)
857686a6 4682 (and (boundp 'lazy-lock-mode) (symbol-value 'lazy-lock-mode)
d3ab8dac 4683 (lazy-lock-fontify-region start end)))
043620f4 4684
ef2cbb24 4685(defun ps-generate-postscript-with-faces (from to)
87a16a06 4686 ;; Some initialization...
857686a6 4687 (setq ps-current-effect 0)
87a16a06 4688
00aa16af 4689 ;; Build the reference lists of faces if necessary.
12d89a2e
RS
4690 (if (or ps-always-build-face-reference
4691 ps-build-face-reference)
4692 (progn
4693 (message "Collecting face information...")
4694 (ps-build-reference-face-lists)))
00aa16af 4695 ;; Generate some PostScript.
ef2cbb24
RS
4696 (save-restriction
4697 (narrow-to-region from to)
d3ab8dac 4698 (ps-print-ensure-fontified from to)
12d89a2e
RS
4699 (let ((face 'default)
4700 (position to))
87a16a06
RS
4701 (cond
4702 ((or (eq ps-print-emacs-type 'lucid)
4703 (eq ps-print-emacs-type 'xemacs))
4704 ;; Build the list of extents...
4705 (let ((a (cons 'dummy nil))
4706 record type extent extent-list)
4707 (map-extents 'ps-mapper nil from to a)
8bd22fcf
KH
4708 (setq a (sort (cdr a) 'car-less-than-car)
4709 extent-list nil)
87a16a06
RS
4710
4711 ;; Loop through the extents...
4712 (while a
8bd22fcf 4713 (setq record (car a)
87a16a06 4714
8bd22fcf
KH
4715 position (car record)
4716 record (cdr record)
87a16a06 4717
8bd22fcf
KH
4718 type (car record)
4719 record (cdr record)
87a16a06 4720
8bd22fcf 4721 extent (car record))
87a16a06
RS
4722
4723 ;; Plot up to this record.
4724 ;; XEmacs 19.12: for some reason, we're getting into a
4725 ;; situation in which some of the records have
4726 ;; positions less than 'from'. Since we've narrowed
4727 ;; the buffer, this'll generate errors. This is a
4728 ;; hack, but don't call ps-plot-with-face unless from >
4729 ;; point-min.
8bd22fcf
KH
4730 (and (>= from (point-min)) (<= position (point-max))
4731 (ps-plot-with-face from position face))
87a16a06
RS
4732
4733 (cond
4734 ((eq type 'push)
d3ab8dac
KH
4735 (and (extent-face extent)
4736 (setq extent-list (sort (cons extent extent-list)
4737 'ps-extent-sorter))))
87a16a06
RS
4738
4739 ((eq type 'pull)
4740 (setq extent-list (sort (delq extent extent-list)
4741 'ps-extent-sorter))))
4742
d3ab8dac
KH
4743 (setq face (if extent-list
4744 (extent-face (car extent-list))
4745 'default)
8bd22fcf
KH
4746 from position
4747 a (cdr a)))))
87a16a06
RS
4748
4749 ((eq ps-print-emacs-type 'emacs)
4750 (let ((property-change from)
e65df0a1
KH
4751 (overlay-change from)
4752 (save-buffer-invisibility-spec buffer-invisibility-spec)
c82b4a75 4753 (buffer-invisibility-spec nil))
87a16a06 4754 (while (< from to)
d3ab8dac 4755 (and (< property-change to) ; Don't search for property change
12d89a2e 4756 ; unless previous search succeeded.
d3ab8dac
KH
4757 (setq property-change (next-property-change from nil to)))
4758 (and (< overlay-change to) ; Don't search for overlay change
12d89a2e 4759 ; unless previous search succeeded.
d3ab8dac
KH
4760 (setq overlay-change (min (next-overlay-change from) to)))
4761 (setq position (min property-change overlay-change))
87a16a06
RS
4762 ;; The code below is not quite correct,
4763 ;; because a non-nil overlay invisible property
4764 ;; which is inactive according to the current value
4765 ;; of buffer-invisibility-spec nonetheless overrides
4766 ;; a face text property.
4767 (setq face
4768 (cond ((let ((prop (get-text-property from 'invisible)))
4769 ;; Decide whether this invisible property
4770 ;; really makes the text invisible.
e65df0a1 4771 (if (eq save-buffer-invisibility-spec t)
87a16a06 4772 (not (null prop))
e65df0a1
KH
4773 (or (memq prop save-buffer-invisibility-spec)
4774 (assq prop save-buffer-invisibility-spec))))
12b88fff 4775 'emacs--invisible--face)
87a16a06
RS
4776 ((get-text-property from 'face))
4777 (t 'default)))
4778 (let ((overlays (overlays-at from))
4779 (face-priority -1)) ; text-property
d3ab8dac
KH
4780 (while (and overlays
4781 (not (eq face 'emacs--invisible--face)))
87a16a06 4782 (let* ((overlay (car overlays))
87a16a06 4783 (overlay-invisible (overlay-get overlay 'invisible))
d3ab8dac 4784 (overlay-priority (or (overlay-get overlay 'priority)
87a16a06 4785 0)))
d3ab8dac 4786 (and (> overlay-priority face-priority)
e65df0a1
KH
4787 (setq face
4788 (cond ((if (eq save-buffer-invisibility-spec t)
4789 (not (null overlay-invisible))
4790 (or (memq overlay-invisible
4791 save-buffer-invisibility-spec)
4792 (assq overlay-invisible
4793 save-buffer-invisibility-spec)))
c82b4a75 4794 'emacs--invisible--face)
d3ab8dac
KH
4795 ((overlay-get overlay 'face))
4796 (t face))
8bd22fcf 4797 face-priority overlay-priority)))
87a16a06
RS
4798 (setq overlays (cdr overlays))))
4799 ;; Plot up to this record.
4800 (ps-plot-with-face from position face)
4801 (setq from position)))))
4802 (ps-plot-with-face from to face))))
ef2cbb24
RS
4803
4804(defun ps-generate-postscript (from to)
12d89a2e 4805 (ps-plot-region from to 0 nil))
ef2cbb24
RS
4806
4807(defun ps-generate (buffer from to genfunc)
87a16a06
RS
4808 (save-excursion
4809 (let ((from (min to from))
4810 (to (max to from))
4811 ;; This avoids trouble if chars with read-only properties
4812 ;; are copied into ps-spool-buffer.
4813 (inhibit-read-only t))
4814 (save-restriction
4815 (narrow-to-region from to)
857686a6
RS
4816 (and ps-razzle-dazzle
4817 (message "Formatting...%3d%%" (setq ps-razchunk 0)))
8bd22fcf
KH
4818 (setq ps-source-buffer buffer
4819 ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
87a16a06
RS
4820 (ps-init-output-queue)
4821 (let (safe-marker completed-safely needs-begin-file)
4822 (unwind-protect
00aa16af
RS
4823 (progn
4824 (set-buffer ps-spool-buffer)
7da17ab6 4825 (set-buffer-multibyte nil)
915293a2 4826
87a16a06
RS
4827 ;; Get a marker and make it point to the current end of the
4828 ;; buffer, If an error occurs, we'll delete everything from
4829 ;; the end of this marker onwards.
4830 (setq safe-marker (make-marker))
4831 (set-marker safe-marker (point-max))
4832
4833 (goto-char (point-min))
8bd22fcf
KH
4834 (or (looking-at (regexp-quote ps-adobe-tag))
4835 (setq needs-begin-file t))
87a16a06
RS
4836 (save-excursion
4837 (set-buffer ps-source-buffer)
7d8b7e8e 4838 (ps-begin-job)
298bfad9
KH
4839 (when needs-begin-file
4840 (ps-begin-file)
4841 (ps-mule-initialize))
298bfad9 4842 (ps-mule-begin-job from to)
87a16a06
RS
4843 (ps-begin-page))
4844 (set-buffer ps-source-buffer)
4845 (funcall genfunc from to)
4846 (ps-end-page)
4847
47d2ac75 4848 (ps-end-file needs-begin-file)
bc0d41bd 4849 (ps-end-job)
87a16a06
RS
4850
4851 ;; Setting this variable tells the unwind form that the
8bd22fcf 4852 ;; the PostScript was generated without error.
87a16a06
RS
4853 (setq completed-safely t))
4854
4855 ;; Unwind form: If some bad mojo occurred while generating
8bd22fcf 4856 ;; PostScript, delete all the PostScript that was generated.
87a16a06
RS
4857 ;; This protects the previously spooled files from getting
4858 ;; corrupted.
8bd22fcf
KH
4859 (and (markerp safe-marker) (not completed-safely)
4860 (progn
4861 (set-buffer ps-spool-buffer)
4862 (delete-region (marker-position safe-marker) (point-max))))))
87a16a06 4863
857686a6 4864 (and ps-razzle-dazzle (message "Formatting...done"))))))
ef2cbb24 4865
e65df0a1 4866
bc0d41bd 4867(defun ps-end-job ()
133fc764 4868 (ps-flush-output)
bc0d41bd
KH
4869 (let ((total-lines (cdr ps-printing-region))
4870 (total-pages (if ps-print-only-one-header
4871 (ps-page-number)
4872 ps-page-count))
4873 case-fold-search)
4874 (set-buffer ps-spool-buffer)
4875 ;; Back to the PS output buffer to set the page count
4876 (goto-char (point-min))
4877 (and (re-search-forward "^/Lines 0 def\n/PageCount 0 def$" nil t)
4878 (replace-match (format "/Lines %d def\n/PageCount %d def"
4879 total-lines total-pages) t))))
7d8b7e8e
KH
4880
4881
6e1b1da6 4882(defconst ps-printer-name-option
906d41a7 4883 (cond (ps-windows-system
6e1b1da6 4884 "-P")
906d41a7 4885 (ps-lp-system
6e1b1da6
GM
4886 "-d")
4887 (t
4888 "-P" )))
4889
4890
857686a6 4891;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
ef2cbb24 4892(defun ps-do-despool (filename)
12d89a2e 4893 (if (or (not (boundp 'ps-spool-buffer))
bcc0d457 4894 (not (symbol-value 'ps-spool-buffer)))
12d89a2e 4895 (message "No spooled PostScript to print")
ef2cbb24
RS
4896 (if filename
4897 (save-excursion
857686a6 4898 (and ps-razzle-dazzle (message "Saving..."))
12d89a2e 4899 (set-buffer ps-spool-buffer)
ef2cbb24 4900 (setq filename (expand-file-name filename))
7ffaf659
EZ
4901 (let ((coding-system-for-write 'raw-text-unix))
4902 (write-region (point-min) (point-max) filename))
857686a6 4903 (and ps-razzle-dazzle (message "Wrote %s" filename)))
ef2cbb24 4904 ;; Else, spool to the printer
857686a6 4905 (and ps-razzle-dazzle (message "Printing..."))
ef2cbb24 4906 (save-excursion
12d89a2e 4907 (set-buffer ps-spool-buffer)
200127fd 4908 (let* ((coding-system-for-write 'raw-text-unix)
298bfad9
KH
4909 (ps-printer-name (or ps-printer-name
4910 (and (boundp 'printer-name)
4911 printer-name)))
200127fd 4912 (ps-lpr-switches
bc0d41bd 4913 (append (and (stringp ps-printer-name)
6e1b1da6
GM
4914 (list (concat ps-printer-name-option
4915 ps-printer-name)))
bc0d41bd 4916 ps-lpr-switches)))
52cf535f
AI
4917 (apply (or ps-print-region-function 'call-process-region)
4918 (point-min) (point-max) ps-lpr-command nil
4919 (and (fboundp 'start-process) 0)
4920 nil
4921 (ps-flatten-list ; dynamic evaluation
4922 (mapcar 'ps-eval-switch ps-lpr-switches)))))
857686a6 4923 (and ps-razzle-dazzle (message "Printing...done")))
12d89a2e
RS
4924 (kill-buffer ps-spool-buffer)))
4925
857686a6
RS
4926;; Dynamic evaluation
4927(defun ps-eval-switch (arg)
4928 (cond ((stringp arg) arg)
4929 ((functionp arg) (apply arg nil))
4930 ((symbolp arg) (symbol-value arg))
4931 ((consp arg) (apply (car arg) (cdr arg)))
4932 (t nil)))
4933
4934;; `ps-flatten-list' is defined here (copied from "message.el" and
4935;; enhanced to handle dotted pairs as well) until we can get some
4936;; sensible autoloads, or `flatten-list' gets put somewhere decent.
4937
4938;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
4939;; => (a b c d e f g h i j)
4940
4941(defun ps-flatten-list (&rest list)
4942 (ps-flatten-list-1 list))
4943
4944(defun ps-flatten-list-1 (list)
4945 (cond ((null list) nil)
4946 ((consp list) (append (ps-flatten-list-1 (car list))
4947 (ps-flatten-list-1 (cdr list))))
4948 (t (list list))))
4949
12d89a2e
RS
4950(defun ps-kill-emacs-check ()
4951 (let (ps-buffer)
8bd22fcf
KH
4952 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
4953 (buffer-modified-p ps-buffer)
4954 (y-or-n-p "Unprinted PostScript waiting; print now? ")
4955 (ps-despool))
4956 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
4957 (buffer-modified-p ps-buffer)
4958 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
4959 (error "Unprinted PostScript"))))
12d89a2e 4960
d3ab8dac
KH
4961(cond ((fboundp 'add-hook)
4962 (funcall 'add-hook 'kill-emacs-hook 'ps-kill-emacs-check))
4963 (kill-emacs-hook
4964 (message "Won't override existing `kill-emacs-hook'"))
4965 (t
4966 (setq kill-emacs-hook 'ps-kill-emacs-check)))
ef2cbb24 4967
298bfad9
KH
4968\f
4969;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12d89a2e 4970;;; Sample Setup Code:
ef2cbb24 4971
0a5daee5 4972
12d89a2e 4973;; This stuff is for anybody that's brave enough to look this far,
87a16a06
RS
4974;; and able to figure out how to use it. It isn't really part of
4975;; ps-print, but I'll leave it here in hopes it might be useful:
ef2cbb24 4976
298bfad9
KH
4977;; WARNING!!! The following code is *sample* code only.
4978;; Don't use it unless you understand what it does!
043620f4 4979
87a16a06
RS
4980(defmacro ps-prsc ()
4981 `(if (eq ps-print-emacs-type 'emacs) [f22] 'f22))
4982(defmacro ps-c-prsc ()
4983 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
4984(defmacro ps-s-prsc ()
4985 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
00aa16af 4986
a18ed129
RS
4987;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
4988;; `ps-left-headers' specially for mail messages.
4989(defun ps-rmail-mode-hook ()
4990 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
4991 (setq ps-header-lines 3
4992 ps-left-header
4993 ;; The left headers will display the message's subject, its
4994 ;; author, and the name of the folder it was in.
4995 '(ps-article-subject ps-article-author buffer-name)))
4996
4997;; See `ps-gnus-print-article-from-summary'. This function does the
4998;; same thing for rmail.
4999(defun ps-rmail-print-message-from-summary ()
5000 (interactive)
5001 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
5002
5003;; Used in `ps-rmail-print-article-from-summary',
5004;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
5005(defun ps-print-message-from-summary (summary-buffer summary-default)
5006 (let ((ps-buf (or (and (boundp summary-buffer)
5007 (symbol-value summary-buffer))
5008 summary-default)))
5009 (and (get-buffer ps-buf)
5010 (save-excursion
5011 (set-buffer ps-buf)
5012 (ps-spool-buffer-with-faces)))))
5013
12d89a2e 5014;; Look in an article or mail message for the Subject: line. To be
87a16a06 5015;; placed in `ps-left-headers'.
12d89a2e 5016(defun ps-article-subject ()
ef2cbb24 5017 (save-excursion
12d89a2e 5018 (goto-char (point-min))
45a870d9 5019 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
edc9cd35 5020 (buffer-substring (match-beginning 1) (match-end 1))
12d89a2e
RS
5021 "Subject ???")))
5022
5023;; Look in an article or mail message for the From: line. Sorta-kinda
5024;; understands RFC-822 addresses and can pull the real name out where
87a16a06 5025;; it's provided. To be placed in `ps-left-headers'.
12d89a2e
RS
5026(defun ps-article-author ()
5027 (save-excursion
5028 (goto-char (point-min))
a97592dd 5029 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
edc9cd35 5030 (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
12d89a2e
RS
5031 (cond
5032
5033 ;; Try first to match addresses that look like
5034 ;; thompson@wg2.waii.com (Jim Thompson)
5035 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
5036 (substring fromstring (match-beginning 1) (match-end 1)))
5037
5038 ;; Next try to match addresses that look like
edc9cd35
GM
5039 ;; Jim Thompson <thompson@wg2.waii.com> or
5040 ;; "Jim Thompson" <thompson@wg2.waii.com>
5041 ((string-match "\\(\"?\\)\\(.*\\)\\1[ \t]+<.*>" fromstring)
5042 (substring fromstring (match-beginning 2) (match-end 2)))
12d89a2e
RS
5043
5044 ;; Couldn't find a real name -- show the address instead.
5045 (t fromstring)))
5046 "From ???")))
5047
a18ed129 5048;; A hook to bind to `gnus-article-prepare-hook'. This will set the
87a16a06
RS
5049;; `ps-left-headers' specially for gnus articles. Unfortunately,
5050;; `gnus-article-mode-hook' is called only once, the first time the *Article*
12d89a2e
RS
5051;; buffer enters that mode, so it would only work for the first time
5052;; we ran gnus. The second time, this hook wouldn't get set up. The
87a16a06 5053;; only alternative is `gnus-article-prepare-hook'.
12d89a2e 5054(defun ps-gnus-article-prepare-hook ()
8bd22fcf
KH
5055 (setq ps-header-lines 3
5056 ps-left-header
12d89a2e
RS
5057 ;; The left headers will display the article's subject, its
5058 ;; author, and the newsgroup it was in.
8bd22fcf 5059 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
12d89a2e 5060
a18ed129
RS
5061;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
5062;; `ps-left-headers' specially for mail messages.
12d89a2e 5063(defun ps-vm-mode-hook ()
00aa16af 5064 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
8bd22fcf
KH
5065 (setq ps-header-lines 3
5066 ps-left-header
12d89a2e
RS
5067 ;; The left headers will display the message's subject, its
5068 ;; author, and the name of the folder it was in.
8bd22fcf 5069 '(ps-article-subject ps-article-author buffer-name)))
12d89a2e
RS
5070
5071;; Every now and then I forget to switch from the *Summary* buffer to
5072;; the *Article* before hitting prsc, and a nicely formatted list of
5073;; article subjects shows up at the printer. This function, bound to
5074;; prsc for the gnus *Summary* buffer means I don't have to switch
5075;; buffers first.
87a16a06 5076;; sb: Updated for Gnus 5.
12d89a2e
RS
5077(defun ps-gnus-print-article-from-summary ()
5078 (interactive)
a18ed129 5079 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
ef2cbb24 5080
87a16a06 5081;; See `ps-gnus-print-article-from-summary'. This function does the
12d89a2e
RS
5082;; same thing for vm.
5083(defun ps-vm-print-message-from-summary ()
5084 (interactive)
a18ed129 5085 (ps-print-message-from-summary 'vm-mail-buffer ""))
ef2cbb24 5086
87a16a06 5087;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
12d89a2e
RS
5088;; prsc.
5089(defun ps-gnus-summary-setup ()
00aa16af 5090 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
12d89a2e
RS
5091
5092;; Look in an article or mail message for the Subject: line. To be
87a16a06 5093;; placed in `ps-left-headers'.
12d89a2e
RS
5094(defun ps-info-file ()
5095 (save-excursion
5096 (goto-char (point-min))
a97592dd 5097 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
edc9cd35 5098 (buffer-substring (match-beginning 1) (match-end 1))
12d89a2e
RS
5099 "File ???")))
5100
5101;; Look in an article or mail message for the Subject: line. To be
87a16a06 5102;; placed in `ps-left-headers'.
12d89a2e
RS
5103(defun ps-info-node ()
5104 (save-excursion
5105 (goto-char (point-min))
a97592dd 5106 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
edc9cd35 5107 (buffer-substring (match-beginning 1) (match-end 1))
12d89a2e
RS
5108 "Node ???")))
5109
5110(defun ps-info-mode-hook ()
5111 (setq ps-left-header
5112 ;; The left headers will display the node name and file name.
8bd22fcf 5113 '(ps-info-node ps-info-file)))
12d89a2e 5114
043620f4
KH
5115;; WARNING! The following function is a *sample* only, and is *not*
5116;; meant to be used as a whole unless you understand what the effects
87a16a06
RS
5117;; will be! (In fact, this is a copy of Jim's setup for ps-print --
5118;; I'd be very surprised if it was useful to *anybody*, without
043620f4
KH
5119;; modification.)
5120
12d89a2e 5121(defun ps-jts-ps-setup ()
00aa16af
RS
5122 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
5123 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
5124 (global-set-key (ps-c-prsc) 'ps-despool)
12d89a2e
RS
5125 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
5126 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
5127 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
00aa16af 5128 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
12d89a2e 5129 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
8bd22fcf
KH
5130 (setq ps-spool-duplex t
5131 ps-print-color-p nil
5132 ps-lpr-command "lpr"
5133 ps-lpr-switches '("-Jjct,duplex_long"))
bcc0d457
RS
5134 'ps-jts-ps-setup)
5135
5136;; WARNING! The following function is a *sample* only, and is *not*
5137;; meant to be used as a whole unless it corresponds to your needs.
5138;; (In fact, this is a copy of Jack's setup for ps-print --
5139;; I would not be that surprised if it was useful to *anybody*,
5140;; without modification.)
5141
5142(defun ps-jack-setup ()
87a16a06 5143 (setq ps-print-color-p nil
bcc0d457 5144 ps-lpr-command "lpr"
8bd22fcf 5145 ps-lpr-switches nil
bcc0d457 5146
87a16a06
RS
5147 ps-paper-type 'a4
5148 ps-landscape-mode t
bcc0d457
RS
5149 ps-number-of-columns 2
5150
5151 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5152 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
5153 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
5154 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5155 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
5156 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
5157 ps-header-line-pad .15
5158 ps-print-header t
5159 ps-print-header-frame t
5160 ps-header-lines 2
5161 ps-show-n-of-n t
5162 ps-spool-duplex nil
5163
5164 ps-font-family 'Courier
5165 ps-font-size 5.5
5166 ps-header-font-family 'Helvetica
5167 ps-header-font-size 6
5168 ps-header-title-font-size 8)
5169 'ps-jack-setup)
12d89a2e 5170
298bfad9
KH
5171\f
5172;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5173;; To make this file smaller, some commands go in a separate file.
5174;; But autoload them here to make the separation invisible.
5175
5176(autoload 'ps-mule-prepare-ascii-font "ps-mule"
5177 "Setup special ASCII font for STRING.
5178STRING should contain only ASCII characters.")
5179
5180(autoload 'ps-mule-set-ascii-font "ps-mule"
5181 "Adjust current font if current charset is not ASCII.")
5182
5183(autoload 'ps-mule-plot-string "ps-mule"
5184 "Generate PostScript code for ploting characters in the region FROM and TO.
5185
5186It is assumed that all characters in this region belong to the same charset.
5187
5188Optional argument BG-COLOR specifies background color.
5189
5190Returns the value:
5191
5192 (ENDPOS . RUN-WIDTH)
5193
5194Where ENDPOS is the end position of the sequence and RUN-WIDTH is the width of
5195the sequence.")
5196
5197(autoload 'ps-mule-initialize "ps-mule"
5198 "Initialize global data for printing multi-byte characters.")
5199
5200(autoload 'ps-mule-begin-job "ps-mule"
5201 "Start printing job for multi-byte chars between FROM and TO.
5202This checks if all multi-byte characters in the region are printable or not.")
5203
5204(autoload 'ps-mule-begin-page "ps-mule"
5205 "Initialize multi-byte charset for printing current page.")
5206
5207\f
5208;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5209
12d89a2e 5210(provide 'ps-print)
b87c5d3d 5211
12d89a2e 5212;;; ps-print.el ends here