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