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