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