(advance_to_char_boundary): Handle the case the code
[bpt/emacs.git] / lisp / ps-print.el
CommitLineData
535efc38 1;;; ps-print.el --- Print text from the buffer as PostScript
12d89a2e 2
27f20fc1 3;; Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
ef2cbb24 4
090be653 5;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
87a16a06 6;; Author: Jacques Duthen <duthen@cegelec-red.fr>
857686a6 7;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
8bd22fcf 8;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
090be653 9;; Keywords: print, PostScript
857686a6
RS
10;; Time-stamp: <97/11/21 22:12:47 vinicius>
11;; Version: 3.05.3
090be653 12
857686a6
RS
13(defconst ps-print-version "3.05.3"
14 "ps-print.el, v 3.05.3 <97/11/21 vinicius>
090be653 15
535efc38 16Vinicius's last change version -- this file may have been edited as part of
090be653
RS
17Emacs without changes to the version number. When reporting bugs,
18please also report the version of Emacs, if any, that ps-print was
19distributed with.
20
21Please send all bug fixes and enhancements to
8bd22fcf 22 Vinicius Jose Latorre <vinicius@cpqd.com.br>.
090be653 23")
ef2cbb24 24
86c10ecb 25;; This file is part of GNU Emacs.
ef2cbb24
RS
26
27;; GNU Emacs is free software; you can redistribute it and/or modify
28;; it under the terms of the GNU General Public License as published by
29;; the Free Software Foundation; either version 2, or (at your option)
30;; any later version.
31
32;; GNU Emacs is distributed in the hope that it will be useful,
33;; but WITHOUT ANY WARRANTY; without even the implied warranty of
34;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35;; GNU General Public License for more details.
36
37;; You should have received a copy of the GNU General Public License
b578f267
EN
38;; along with GNU Emacs; see the file COPYING. If not, write to the
39;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
40;; Boston, MA 02111-1307, USA.
ef2cbb24 41
12d89a2e 42;;; Commentary:
ef2cbb24
RS
43
44;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45;;
12d89a2e 46;; About ps-print
ef2cbb24 47;; --------------
bcc0d457 48;;
ef2cbb24
RS
49;; This package provides printing of Emacs buffers on PostScript
50;; printers; the buffer's bold and italic text attributes are
51;; preserved in the printer output. Ps-print is intended for use with
00aa16af
RS
52;; Emacs 19 or Lucid Emacs, together with a fontifying package such as
53;; font-lock or hilit.
12d89a2e 54;;
87a16a06
RS
55;; ps-print uses the same face attributes defined through font-lock or hilit
56;; to print a PostScript file, but some faces are better seeing on the screen
57;; than on paper, specially when you have a black/white PostScript printer.
58;;
59;; ps-print allows a remap of face to another one that it is better to print,
60;; for example, the face font-lock-comment-face (if you are using font-lock)
61;; could have bold or italic attribute when printing, besides foreground color.
62;; This remap improves printing look (see How Ps-Print Maps Faces).
63;;
bcc0d457 64;;
12d89a2e 65;; Using ps-print
ef2cbb24 66;; --------------
ef2cbb24 67;;
12d89a2e
RS
68;; The Commands
69;;
70;; Ps-print provides eight commands for generating PostScript images
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;;
1061ff16 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;;
184;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
185;; from the variables `lpr-command' and `lpr-switches'. If you have
186;; `lpr-command' set to invoke a pretty-printer such as `enscript',
187;; then ps-print won't work properly. `ps-lpr-command' must name
12d89a2e
RS
188;; a program that does not format the files it prints.
189;;
190;;
bcc0d457
RS
191;; The Page Layout
192;; ---------------
12d89a2e 193;;
bcc0d457
RS
194;; All dimensions are floats in PostScript points.
195;; 1 inch == 2.54 cm == 72 points
196;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
12d89a2e 197;;
bcc0d457
RS
198;; The variable `ps-paper-type' determines the size of paper ps-print
199;; formats for; it should contain one of the symbols:
200;; `a4' `a3' `letter' `legal' `letter-small' `tabloid'
201;; `ledger' `statement' `executive' `a4small' `b4' `b5'
12d89a2e 202;;
bcc0d457
RS
203;; The variable `ps-landscape-mode' determines the orientation
204;; of the printing on the page:
205;; nil means `portrait' mode, non-nil means `landscape' mode.
206;; There is no oblique mode yet, though this is easy to do in ps.
87a16a06 207;;
bcc0d457
RS
208;; In landscape mode, the text is NOT scaled: you may print 70 lines
209;; in portrait mode and only 50 lignes in landscape mode.
210;; The margins represent margins in the printed paper:
211;; the top margin is the margin between the top of the page
212;; and the printed header, whatever the orientation is.
043620f4 213;;
bcc0d457
RS
214;; The variable `ps-number-of-columns' determines the number of columns
215;; both in landscape and portrait mode.
216;; You can use:
217;; - (the standard) one column portrait mode
218;; - (my favorite) two columns landscape mode (which spares trees)
219;; but also
220;; - one column landscape mode for files with very long lines.
221;; - multi-column portrait or landscape mode
12d89a2e 222;;
12d89a2e 223;;
bcc0d457
RS
224;; Horizontal layout
225;; -----------------
12d89a2e 226;;
bcc0d457
RS
227;; The horizontal layout is determined by the variables
228;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
229;; as follows:
12d89a2e 230;;
bcc0d457
RS
231;; ------------------------------------------
232;; | | | | | | | |
233;; | lm | text | ic | text | ic | text | rm |
234;; | | | | | | | |
235;; ------------------------------------------
12d89a2e 236;;
bcc0d457
RS
237;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
238;; Usually, lm = rm > 0 and ic = lm
239;; If (ic < 0), the text of adjacent columns can overlap.
12d89a2e 240;;
12d89a2e 241;;
bcc0d457
RS
242;; Vertical layout
243;; ---------------
244;;
245;; The vertical layout is determined by the variables
246;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
247;; as follows:
248;;
249;; |--------| |--------|
250;; | tm | | tm |
251;; |--------| |--------|
252;; | header | | |
253;; |--------| | |
254;; | ho | | |
255;; |--------| or | text |
256;; | | | |
257;; | text | | |
258;; | | | |
259;; |--------| |--------|
260;; | bm | | bm |
261;; |--------| |--------|
262;;
263;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
264;; The margins represent margins in the printed paper:
265;; the top margin is the margin between the top of the page
266;; and the printed header, whatever the orientation is.
12d89a2e
RS
267;;
268;;
269;; Headers
bcc0d457 270;; -------
12d89a2e 271;;
bcc0d457 272;; Ps-print can print headers at the top of each column; the default
12d89a2e
RS
273;; headers contain the following four items: on the left, the name of
274;; the buffer and, if the buffer is visiting a file, the file's
bcc0d457
RS
275;; directory; on the right, the page number and date of printing.
276;; The default headers look something like this:
12d89a2e
RS
277;;
278;; ps-print.el 1/21
279;; /home/jct/emacs-lisp/ps/new 94/12/31
06fb6aab 280;;
12d89a2e 281;; When printing on duplex printers, left and right are reversed so
bcc0d457 282;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
12d89a2e 283;;
bcc0d457
RS
284;; Headers are configurable:
285;; To turn them off completely, set `ps-print-header' to nil.
286;; To turn off the header's gaudy framing box,
287;; set `ps-print-header-frame' to nil.
288;;
289;; The font family and size of text in the header are determined
06fb6aab 290;; by the variables `ps-header-font-family', `ps-header-font-size' and
bcc0d457
RS
291;; `ps-header-title-font-size' (see below).
292;;
293;; The variable `ps-header-line-pad' determines the portion of a header
294;; title line height to insert between the header frame and the text
295;; it contains, both in the vertical and horizontal directions:
296;; .5 means half a line.
297
298;; Page numbers are printed in `n/m' format, indicating page n of m pages;
299;; to omit the total page count and just print the page number,
300;; set `ps-show-n-of-n' to nil.
12d89a2e
RS
301;;
302;; The amount of information in the header can be changed by changing
bcc0d457 303;; the number of lines. To show less, set `ps-header-lines' to 1, and
12d89a2e 304;; the header will show only the buffer name and page number. To show
bcc0d457 305;; more, set `ps-header-lines' to 3, and the header will show the time of
12d89a2e
RS
306;; printing below the date.
307;;
308;; To change the content of the headers, change the variables
bcc0d457
RS
309;; `ps-left-header' and `ps-right-header'.
310;; These variables are lists, specifying top-to-bottom the text
311;; to display on the left or right side of the header.
312;; Each element of the list should be a string or a symbol.
313;; Strings are inserted directly into the PostScript arrays,
314;; and should contain the PostScript string delimiters '(' and ')'.
12d89a2e
RS
315;;
316;; Symbols in the header format lists can either represent functions
317;; or variables. Functions are called, and should return a string to
318;; show in the header. Variables should contain strings to display in
319;; the header. In either case, function or variable, the PostScript
a7acbbe4 320;; string delimiters are added by ps-print, and should not be part of
12d89a2e
RS
321;; the returned value.
322;;
323;; Here's an example: say we want the left header to display the text
324;;
325;; Moe
326;; Larry
327;; Curly
328;;
329;; where we have a function to return "Moe"
330;;
331;; (defun moe-func ()
332;; "Moe")
333;;
334;; a variable specifying "Larry"
335;;
336;; (setq larry-var "Larry")
337;;
bcc0d457 338;; and a literal for "Curly". Here's how `ps-left-header' should be
12d89a2e
RS
339;; set:
340;;
341;; (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
342;;
343;; Note that Curly has the PostScript string delimiters inside his
bcc0d457 344;; quotes -- those aren't misplaced lisp delimiters!
87a16a06 345;;
bcc0d457
RS
346;; Without them, PostScript would attempt to call the undefined
347;; function Curly, which would result in a PostScript error.
87a16a06 348;;
bcc0d457
RS
349;; Since most printers don't report PostScript errors except by
350;; aborting the print job, this kind of error can be hard to track down.
87a16a06 351;;
bcc0d457 352;; Consider yourself warned!
12d89a2e
RS
353;;
354;;
355;; Duplex Printers
bcc0d457 356;; ---------------
12d89a2e
RS
357;;
358;; If you have a duplex-capable printer (one that prints both sides of
bcc0d457
RS
359;; the paper), set `ps-spool-duplex' to t.
360;; Ps-print will insert blank pages to make sure each buffer starts
361;; on the correct side of the paper.
362;; Don't forget to set `ps-lpr-switches' to select duplex printing
363;; for your printer.
364;;
06fb6aab 365;;
857686a6
RS
366;; Control And 8-bit Characters
367;; ----------------------------
368;;
369;; The variable `ps-print-control-characters' specifies whether you want to see
370;; a printable form for control and 8-bit characters, that is, instead of
371;; sending, for example, a ^D (\005) to printer, it is sent the string "^D".
372;;
373;; Valid values for `ps-print-control-characters' are:
374;;
375;; '8-bit printable form for control and 8-bit characters
376;; (characters from \000 to \037 and \177 to \377).
377;; 'control-8-bit printable form for control and *control* 8-bit characters
378;; (characters from \000 to \037 and \177 to \237).
379;; 'control printable form for control character
380;; (characters from \000 to \037 and \177).
381;; nil raw character (no printable form).
382;;
383;; Any other value is treated as nil.
384;;
385;; The default is 'control-8-bit.
386;;
387;; Characters TAB, NEWLINE and FORMFEED are always treated by ps-print engine.
388;;
389;;
87a16a06
RS
390;; Line Number
391;; -----------
392;;
a18ed129
RS
393;; The variable `ps-line-number' specifies whether to number each line;
394;; non-nil means do so. The default is nil (don't number each line).
87a16a06
RS
395;;
396;;
397;; Zebra Stripes
398;; -------------
399;;
a18ed129
RS
400;; Zebra stripes are a kind of background that appear "underneath" the text
401;; and can make the text easier to read. They look like this:
87a16a06
RS
402;;
403;; XXXXXXXXXXXXXXXXXXXXXXXX
404;; XXXXXXXXXXXXXXXXXXXXXXXX
535efc38
RS
405;; XXXXXXXXXXXXXXXXXXXXXXXX
406;;
87a16a06
RS
407;;
408;;
409;; XXXXXXXXXXXXXXXXXXXXXXXX
410;; XXXXXXXXXXXXXXXXXXXXXXXX
535efc38 411;; XXXXXXXXXXXXXXXXXXXXXXXX
87a16a06 412;;
06fb6aab 413;; The blocks of X's represent rectangles filled with a light gray color.
a18ed129
RS
414;; Each rectangle extends all the way across the page.
415;;
416;; The height, in lines, of each rectangle is controlled by
535efc38
RS
417;; the variable `ps-zebra-stripe-height', which is 3 by default.
418;; The distance between stripes equals the height of a stripe.
8bd22fcf 419;;
01961237 420;; The variable `ps-zebra-stripes' controls whether to print zebra stripes.
a18ed129
RS
421;; Non-nil means yes, nil means no. The default is nil.
422;;
423;; See also section How Ps-Print Has A Text And/Or Image On Background.
87a16a06 424;;
87a16a06 425;;
bcc0d457
RS
426;; Font managing
427;; -------------
428;;
429;; Ps-print now knows rather precisely some fonts:
430;; the variable `ps-font-info-database' contains information
431;; for a list of font families (currently mainly `Courier' `Helvetica'
432;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk').
433;; Each font family contains the font names for standard, bold, italic
434;; and bold-italic characters, a reference size (usually 10) and the
435;; corresponding line height, width of a space and average character width.
06fb6aab 436;;
bcc0d457
RS
437;; The variable `ps-font-family' determines which font family
438;; is to be used for ordinary text.
439;; If its value does not correspond to a known font family,
440;; an error message is printed into the `*Messages*' buffer,
441;; which lists the currently available font families.
442;;
443;; The variable `ps-font-size' determines the size (in points)
444;; of the font for ordinary text, when generating Postscript.
445;; Its value is a float.
446;;
447;; Similarly, the variable `ps-header-font-family' determines
448;; which font family is to be used for text in the header.
449;; The variable `ps-header-font-size' determines the font size,
450;; in points, for text in the header.
451;; The variable `ps-header-title-font-size' determines the font size,
452;; in points, for the top line of text in the header.
453;;
454;;
455;; Adding a new font family
456;; ------------------------
457;;
458;; To use a new font family, you MUST first teach ps-print
87a16a06 459;; this font, i.e., add its information to `ps-font-info-database',
bcc0d457
RS
460;; otherwise ps-print cannot correctly place line and page breaks.
461;;
87a16a06 462;; For example, assuming `Helvetica' is unknown,
bcc0d457
RS
463;; you first need to do the following ONLY ONCE:
464;;
465;; - create a new buffer
466;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
467;; - open this file and find the line:
468;; `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
a18ed129 469;; - delete the leading `%' (which is the PostScript comment character)
bcc0d457
RS
470;; - replace in this line `Courier' by the new font (say `Helvetica')
471;; to get the line:
472;; `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
473;; - send this file to the printer (or to ghostscript).
474;; You should read the following on the output page:
475;;
476;; For Helvetica 10 point, the line height is 11.56, the space width is 2.78
477;; and a crude estimate of average character width is 5.09243
478;;
479;; - Add these values to the `ps-font-info-database':
480;; (setq ps-font-info-database
481;; (append
482;; '((Helvetica ; the family name
483;; "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
484;; 10.0 11.56 2.78 5.09243))
485;; ps-font-info-database))
486;; - Now you can use this font family with any size:
487;; (setq ps-font-family 'Helvetica)
488;; - if you want to use this family in another emacs session, you must
489;; put into your `~/.emacs':
490;; (require 'ps-print)
491;; (setq ps-font-info-database (append ...)))
492;; if you don't want to load ps-print, you have to copy the whole value:
493;; (setq ps-font-info-database '(<your stuff> <the standard stuff>))
494;; or, if you can wait until the `ps-print-hook' is implemented, do:
495;; (add-hook 'ps-print-hook '(setq ps-font-info-database (append ...)))
496;; This does not work yet, since there is no `ps-print-hook' yet.
497;;
498;; You can create new `mixed' font families like:
499;; (my-mixed-family
500;; "Courier-Bold" "Helvetica"
501;; "Zapf-Chancery-MediumItalic" "NewCenturySchlbk-BoldItalic"
502;; 10.0 10.55 6.0 6.0)
503;; Now you can use your new font family with any size:
504;; (setq ps-font-family 'my-mixed-family)
505;;
506;; You can get information on all the fonts resident in YOUR printer
507;; by uncommenting the line:
508;; % 3 cm 20 cm moveto ReportAllFontInfo showpage
509;;
a18ed129
RS
510;; The PostScript file should be sent to YOUR PostScript printer.
511;; If you send it to ghostscript or to another PostScript printer,
bcc0d457
RS
512;; you may get slightly different results.
513;; Anyway, as ghostscript fonts are autoload, you won't get
514;; much font info.
515;;
516;;
517;; How Ps-Print Deals With Faces
518;; -----------------------------
12d89a2e 519;;
bcc0d457
RS
520;; The ps-print-*-with-faces commands attempt to determine which faces
521;; should be printed in bold or italic, but their guesses aren't
522;; always right. For example, you might want to map colors into faces
523;; so that blue faces print in bold, and red faces in italic.
12d89a2e 524;;
857686a6
RS
525;; It is possible to force ps-print to consider specific faces bold,
526;; italic or underline, no matter what font they are displayed in, by setting
527;; the variables `ps-bold-faces', `ps-italic-faces' and `ps-underlined-faces'.
528;; These variables contain lists of faces that ps-print should consider bold,
529;; italic or underline; to set them, put code like the following into your
530;; .emacs file:
12d89a2e 531;;
bcc0d457
RS
532;; (setq ps-bold-faces '(my-blue-face))
533;; (setq ps-italic-faces '(my-red-face))
857686a6 534;; (setq ps-underlined-faces '(my-green-face))
bcc0d457
RS
535;;
536;; Faces like bold-italic that are both bold and italic should go in
537;; *both* lists.
538;;
539;; Ps-print keeps internal lists of which fonts are bold and which are
540;; italic; these lists are built the first time you invoke ps-print.
541;; For the sake of efficiency, the lists are built only once; the same
542;; lists are referred in later invocations of ps-print.
543;;
544;; Because these lists are built only once, it's possible for them to
545;; get out of sync, if a face changes, or if new faces are added. To
546;; get the lists back in sync, you can set the variable
547;; `ps-build-face-reference' to t, and the lists will be rebuilt the
857686a6
RS
548;; next time ps-print is invoked. If you need that the lists always be
549;; rebuilt when ps-print is invoked, set the variable
550;; `ps-always-build-face-reference' to t.
bcc0d457
RS
551;;
552;;
553;; How Ps-Print Deals With Color
554;; -----------------------------
555;;
556;; Ps-print detects faces with foreground and background colors
557;; defined and embeds color information in the PostScript image.
558;; The default foreground and background colors are defined by the
559;; variables `ps-default-fg' and `ps-default-bg'.
560;; On black-and-white printers, colors are displayed in grayscale.
561;; To turn off color output, set `ps-print-color-p' to nil.
562;;
563;;
87a16a06
RS
564;; How Ps-Print Maps Faces
565;; -----------------------
566;;
567;; As ps-print uses PostScript to print buffers, it is possible to have
568;; other attributes associated with faces. So the new attributes used
569;; by ps-print are:
570;;
571;; strikeout - like underline, but the line is in middle of text.
572;; overline - like underline, but the line is over the text.
573;; shadow - text will have a shadow.
574;; box - text will be surrounded by a box.
a18ed129 575;; outline - print characters as hollow outlines.
87a16a06 576;;
06fb6aab 577;; See the documentation for `ps-extend-face'.
87a16a06
RS
578;;
579;; Let's, for example, remap font-lock-keyword-face to another foreground color
580;; and bold attribute:
581;;
a18ed129 582;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE)
87a16a06 583;;
6c8f2753
RS
584;; If you want to use a new face, define it first with `defface',
585;; and then call `ps-extend-face' to specify how to print it.
586;;
87a16a06
RS
587;;
588;; How Ps-Print Has A Text And/Or Image On Background
589;; --------------------------------------------------
590;;
591;; Ps-print can print texts and/or EPS PostScript images on background; it is
592;; possible to define the following text attributes: font name, font size,
593;; initial position, angle, gray scale and pages to print.
594;;
595;; It has the following EPS PostScript images attributes: file name containing
596;; the image, initial position, X and Y scales, angle and pages to print.
597;;
598;; See documentation for `ps-print-background-text' and
599;; `ps-print-background-image'.
600;;
601;; For example, if we wish to print text "preliminary" on all pages and text
602;; "special" on page 5 and from page 11 to page 17, we could specify:
603;;
604;; (setq ps-print-background-text
605;; '(("preliminary")
606;; ("special"
607;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
608;; ; (upper left corner)
609;; nil nil nil
610;; "PrintHeight neg PrintWidth atan" ; angle
611;; 5 (11 . 17)) ; page list
612;; ))
613;;
614;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
615;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
616;; specify:
617;;
618;; (setq ps-print-background-image
619;; '(("~/images/EPS-image1.ps"
620;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
621;; ("~/images/EPS-image2.ps"
622;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
623;; ; (upper left corner)
624;; nil nil nil
625;; 5 (11 . 17)) ; page list
626;; ))
627;;
628;; If it is not possible to read (or does not exist) an image file, that file
629;; is ignored.
630;;
631;; The printing order is:
632;;
633;; 1. Print zebra stripes
634;; 2. Print background texts that it should be on all pages
635;; 3. Print background images that it should be on all pages
636;; 4. Print background texts only for current page (if any)
637;; 5. Print background images only for current page (if any)
638;; 6. Print header
a18ed129 639;; 7. Print buffer text (with faces, if specified) and line number
87a16a06
RS
640;;
641;;
bcc0d457
RS
642;; Utilities
643;; ---------
644;;
645;; Some tools are provided to help you customize your font setup.
646;;
647;; `ps-setup' returns (some part of) the current setup.
648;;
649;; To avoid wrapping too many lines, you may want to adjust the
650;; left and right margins and the font size. On UN*X systems, do:
651;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
652;; to determine the longest lines of your file.
87a16a06 653;; Then, the command `ps-line-lengths' will give you the correspondence
bcc0d457
RS
654;; between a line length (number of characters) and the maximum font
655;; size which doesn't wrap such a line with the current ps-print setup.
656;;
657;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
87a16a06 658;; the correspondence between a number of pages and the maximum font
bcc0d457
RS
659;; size which allow the number of lines of the current buffer or of
660;; its current region to fit in this number of pages.
a18ed129
RS
661;;
662;; NOTE: line folding is not taken into account in this process and could
663;; change the results.
b87c5d3d 664;;
b87c5d3d 665;;
b87c5d3d
RS
666;; New since version 1.5
667;; ---------------------
b87c5d3d 668;;
bcc0d457 669;; Color output capability.
b87c5d3d 670;; Automatic detection of font attributes (bold, italic).
b87c5d3d 671;; Configurable headers with page numbers.
b87c5d3d 672;; Slightly faster.
b87c5d3d 673;; Support for different paper sizes.
b87c5d3d
RS
674;; Better conformance to PostScript Document Structure Conventions.
675;;
ef2cbb24 676;;
bcc0d457
RS
677;; New since version 2.8
678;; ---------------------
679;;
857686a6 680;; [vinicius] 971121 Vinicius Jose Latorre <vinicius@cpqd.com.br>
87a16a06
RS
681;;
682;; Handle control characters.
683;; Face remapping.
684;; New face attributes.
685;; Line number.
686;; Zebra stripes.
687;; Text and/or image on background.
688;;
bcc0d457
RS
689;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
690;;
a18ed129 691;; Font family and float size for text and header.
bcc0d457
RS
692;; Landscape mode.
693;; Multiple columns.
694;; Tools for page setup.
695;;
696;;
ef2cbb24
RS
697;; Known bugs and limitations of ps-print:
698;; --------------------------------------
bcc0d457 699;;
043620f4
KH
700;; Although color printing will work in XEmacs 19.12, it doesn't work
701;; well; in particular, bold or italic fonts don't print in the right
702;; background color.
703;;
704;; Invisible properties aren't correctly ignored in XEmacs 19.12.
705;;
b87c5d3d 706;; Automatic font-attribute detection doesn't work well, especially
00aa16af 707;; with hilit19 and older versions of get-create-face. Users having
bcc0d457 708;; problems with auto-font detection should use the lists
857686a6
RS
709;; `ps-italic-faces', `ps-bold-faces' and `ps-underlined-faces' and/or
710;; turn off automatic detection by setting `ps-auto-font-detect' to nil.
00aa16af 711;;
043620f4 712;; Automatic font-attribute detection doesn't work with XEmacs 19.12
857686a6
RS
713;; in tty mode; use the lists `ps-italic-faces', `ps-bold-faces' and
714;; `ps-underlined-faces' instead.
12d89a2e 715;;
00aa16af 716;; Still too slow; could use some hand-optimization.
ef2cbb24 717;;
12d89a2e 718;; Default background color isn't working.
ef2cbb24
RS
719;;
720;; Faces are always treated as opaque.
721;;
12d89a2e 722;; Epoch and Emacs 18 not supported. At all.
ef2cbb24 723;;
06fb6aab 724;; Fixed-pitch fonts work better for line folding, but are not required.
bcc0d457
RS
725;;
726;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
727;; of folding lines.
ef2cbb24 728;;
12d89a2e 729;;
bcc0d457
RS
730;; Things to change:
731;; ----------------
ef2cbb24 732;;
bcc0d457
RS
733;; Add `ps-print-hook' (I don't know how to do that (yet!)).
734;; Add 4-up capability (really needed?).
bcc0d457
RS
735;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
736;; Put one header per page over the columns (easy but needed?).
737;; Improve the memory management for big files (hard?).
738;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
739;; of folding lines.
ef2cbb24 740;;
ef2cbb24 741;;
12d89a2e
RS
742;; Acknowledgements
743;; ----------------
857686a6
RS
744;; Thanks to Jacques Duthen <duthen@cegelec-red.fr> (Jack) for the 3.4 version
745;; I started from. [vinicius]
746;;
bcc0d457
RS
747;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
748;; [jack]
749;;
12d89a2e
RS
750;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
751;; color and the invisible property.
ef2cbb24 752;;
12d89a2e
RS
753;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
754;; the initial port to Emacs 19. His code is no longer part of
755;; ps-print, but his work is still appreciated.
ef2cbb24 756;;
12d89a2e
RS
757;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
758;; for adding underline support. Their code also is no longer part of
759;; ps-print, but their efforts are not forgotten.
760;;
761;; Thanks also to all of you who mailed code to add features to
762;; ps-print; although I didn't use your code, I still appreciate your
763;; sharing it with me.
764;;
765;; Thanks to all who mailed comments, encouragement, and criticism.
766;; Thanks also to all who responded to my survey; I had too many
767;; responses to reply to them all, but I greatly appreciate your
768;; interest.
769;;
770;; Jim
771;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ef2cbb24
RS
772
773;;; Code:
774
090be653
RS
775(eval-when-compile
776 (require 'cl))
b87c5d3d 777
090be653
RS
778(unless (featurep 'lisp-float-type)
779 (error "`ps-print' requires floating point support"))
ef2cbb24
RS
780
781;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12d89a2e
RS
782;; User Variables:
783
bcc0d457
RS
784;;; Interface to the command system
785
e0af0d3e 786(defgroup ps-print nil
8bd22fcf 787 "PostScript generator for Emacs 19"
e0af0d3e
RS
788 :prefix "ps-"
789 :group 'wp)
790
791(defgroup ps-print-horizontal nil
792 "Horizontal page layout"
793 :prefix "ps-"
794 :tag "Horizontal"
795 :group 'ps-print)
796
797(defgroup ps-print-vertical nil
798 "Vertical page layout"
799 :prefix "ps-"
800 :tag "Vertical"
801 :group 'ps-print)
802
803(defgroup ps-print-header nil
804 "Headers layout"
805 :prefix "ps-"
806 :tag "Header"
807 :group 'ps-print)
808
809(defgroup ps-print-font nil
810 "Fonts customization"
811 :prefix "ps-"
812 :tag "Font"
813 :group 'ps-print)
814
815(defgroup ps-print-color nil
816 "Color customization"
817 :prefix "ps-"
818 :tag "Color"
819 :group 'ps-print)
820
821(defgroup ps-print-face nil
822 "Faces customization"
823 :prefix "ps-"
824 :tag "PS Faces"
825 :group 'ps-print
826 :group 'faces)
827
828
829(defcustom ps-lpr-command lpr-command
830 "*The shell command for printing a PostScript file."
831 :type 'string
832 :group 'ps-print)
833
834(defcustom ps-lpr-switches lpr-switches
835 "*A list of extra switches to pass to `ps-lpr-command'."
836 :type '(repeat string)
837 :group 'ps-print)
12d89a2e 838
bcc0d457 839;;; Page layout
12d89a2e 840
bcc0d457
RS
841;; All page dimensions are in PostScript points.
842;; 1 inch == 2.54 cm == 72 points
843;; 1 cm == (/ 1 2.54) inch == (/ 72 2.54) points
844
845;; Letter 8.5 inch x 11.0 inch
846;; Legal 8.5 inch x 14.0 inch
847;; A4 8.26 inch x 11.69 inch = 21.0 cm x 29.7 cm
848
849;; LetterSmall 7.68 inch x 10.16 inch
850;; Tabloid 11.0 inch x 17.0 inch
851;; Ledger 17.0 inch x 11.0 inch
852;; Statement 5.5 inch x 8.5 inch
853;; Executive 7.5 inch x 10.0 inch
854;; A3 11.69 inch x 16.5 inch = 29.7 cm x 42.0 cm
855;; A4Small 7.47 inch x 10.85 inch
856;; B4 10.125 inch x 14.33 inch
857;; B5 7.16 inch x 10.125 inch
858
e0af0d3e 859(defcustom ps-page-dimensions-database
bcc0d457
RS
860 (list (list 'a4 (/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54))
861 (list 'a3 (/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54))
862 (list 'letter (* 72 8.5) (* 72 11.0))
863 (list 'legal (* 72 8.5) (* 72 14.0))
864 (list 'letter-small (* 72 7.68) (* 72 10.16))
865 (list 'tabloid (* 72 11.0) (* 72 17.0))
866 (list 'ledger (* 72 17.0) (* 72 11.0))
867 (list 'statement (* 72 5.5) (* 72 8.5))
868 (list 'executive (* 72 7.5) (* 72 10.0))
869 (list 'a4small (* 72 7.47) (* 72 10.85))
870 (list 'b4 (* 72 10.125) (* 72 14.33))
871 (list 'b5 (* 72 7.16) (* 72 10.125)))
872 "*List associating a symbolic paper type to its width and height.
e0af0d3e
RS
873see `ps-paper-type'."
874 :type '(repeat (list :tag "Paper Type"
875 (symbol :tag "Name")
876 (number :tag "Width")
877 (number :tag "Height")))
878 :group 'ps-print)
879
857686a6 880;;;###autoload
e0af0d3e 881(defcustom ps-paper-type 'letter
bcc0d457 882 "*Specifies the size of paper to format for.
090be653 883Should be one of the paper types defined in `ps-page-dimensions-database', for
e0af0d3e
RS
884example `letter', `legal' or `a4'."
885 :type '(symbol :validate (lambda (wid)
87a16a06
RS
886 (if (assq (widget-value wid)
887 ps-page-dimensions-database)
e0af0d3e
RS
888 nil
889 (widget-put wid :error "Unknown paper size")
890 wid)))
891 :group 'ps-print)
892
87a16a06 893(defcustom ps-landscape-mode nil
e0af0d3e
RS
894 "*Non-nil means print in landscape mode."
895 :type 'boolean
896 :group 'ps-print)
897
857686a6
RS
898(defcustom ps-print-control-characters 'control-8-bit
899 "*Specifies the printable form for control and 8-bit characters.
900Valid values are:
901 '8-bit printable form for control and 8-bit characters
902 (characters from \000 to \037 and \177 to \377).
903 'control-8-bit printable form for control and *control* 8-bit characters
904 (characters from \000 to \037 and \177 to \237).
905 'control printable form for control character
906 (characters from \000 to \037 and \177).
907 nil raw character (no printable form).
908Any other value is treated as nil."
909 :type '(choice (const 8-bit) (const control-8-bit) (const control) (const nil))
910 :group 'ps-print)
911
e0af0d3e
RS
912(defcustom ps-number-of-columns (if ps-landscape-mode 2 1)
913 "*Specifies the number of columns"
87a16a06
RS
914 :type 'number
915 :group 'ps-print)
916
535efc38 917(defcustom ps-zebra-stripes nil
87a16a06 918 "*Non-nil means print zebra stripes.
06fb6aab 919See also documentation for `ps-zebra-stripe-height'."
87a16a06
RS
920 :type 'boolean
921 :group 'ps-print)
922
535efc38 923(defcustom ps-zebra-stripe-height 3
87a16a06 924 "*Number of zebra stripe lines.
06fb6aab 925See also documentation for `ps-zebra-stripes'."
87a16a06
RS
926 :type 'number
927 :group 'ps-print)
928
929(defcustom ps-line-number nil
930 "*Non-nil means print line number."
931 :type 'boolean
932 :group 'ps-print)
933
934(defcustom ps-print-background-image nil
935 "*EPS image list to be printed on background.
936
937The elements are:
938
939 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
940
941FILENAME is a file name which contains an EPS image or some PostScript
942programming like EPS.
943FILENAME is ignored, if it doesn't exist or is read protected.
944
945X and Y are relative positions on paper to put the image.
946If X and Y are nil, the image is centralized on paper.
947
948XSCALE and YSCALE are scale factor to be applied to image before printing.
949If XSCALE and YSCALE are nil, the original size is used.
950
951ROTATION is the image rotation angle; if nil, the default is 0.
952
953PAGES designates the page to print background image.
954PAGES may be a number or a cons cell (FROM . TO) designating FROM page
955to TO page.
956If PAGES is nil, print background image on all pages.
957
958X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
959an integer number or a string. If it is a string, the string should contain
960PostScript programming that returns a float or integer value.
961
962For example, if you wish to print an EPS image on all pages do:
963
964 '((\"~/images/EPS-image.ps\"))"
35378a09
KH
965 :type '(repeat (list file
966 (choice :tag "X" number string (const nil))
967 (choice :tag "Y" number string (const nil))
968 (choice :tag "X Scale" number string (const nil))
969 (choice :tag "Y Scale" number string (const nil))
970 (choice :tag "Rotation" number string (const nil))
971 (repeat :tag "Pages" :inline t
972 (radio integer
973 (cons :tag "Range"
974 (integer :tag "From")
975 (integer :tag "To"))))))
87a16a06
RS
976 :group 'ps-print)
977
978(defcustom ps-print-background-text nil
979 "*Text list to be printed on background.
980
981The elements are:
982
983 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
984
985STRING is the text to be printed on background.
986
987X and Y are positions on paper to put the text.
988If X and Y are nil, the text is positioned at lower left corner.
989
990FONT is a font name to be used on printing the text.
991If nil, \"Times-Roman\" is used.
992
993FONTSIZE is font size to be used, if nil, 200 is used.
994
995GRAY is the text gray factor (should be very light like 0.8).
996If nil, the default is 0.85.
997
998ROTATION is the text rotation angle; if nil, the angle is given by
999the diagonal from lower left corner to upper right corner.
1000
1001PAGES designates the page to print background text.
1002PAGES may be a number or a cons cell (FROM . TO) designating FROM page
1003to TO page.
1004If PAGES is nil, print background text on all pages.
1005
1006X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
1007an integer number or a string. If it is a string, the string should contain
1008PostScript programming that returns a float or integer value.
1009
1010For example, if you wish to print text \"Preliminary\" on all pages do:
1011
1012 '((\"Preliminary\"))"
35378a09
KH
1013 :type '(repeat (list string
1014 (choice :tag "X" number string (const nil))
1015 (choice :tag "Y" number string (const nil))
1016 (choice :tag "Font" string (const nil))
1017 (choice :tag "Fontsize" number string (const nil))
1018 (choice :tag "Gray" number string (const nil))
1019 (choice :tag "Rotation" number string (const nil))
1020 (repeat :tag "Pages" :inline t
1021 (radio integer
1022 (cons :tag "Range"
1023 (integer :tag "From")
1024 (integer :tag "To"))))))
e0af0d3e 1025 :group 'ps-print)
bcc0d457
RS
1026
1027;;; Horizontal layout
1028
1029;; ------------------------------------------
1030;; | | | | | | | |
1031;; | lm | text | ic | text | ic | text | rm |
1032;; | | | | | | | |
1033;; ------------------------------------------
1034
e0af0d3e
RS
1035(defcustom ps-left-margin (/ (* 72 2.0) 2.54) ; 2 cm
1036 "*Left margin in points (1/72 inch)."
1037 :type 'number
1038 :group 'ps-print-horizontal)
bcc0d457 1039
e0af0d3e
RS
1040(defcustom ps-right-margin (/ (* 72 2.0) 2.54) ; 2 cm
1041 "*Right margin in points (1/72 inch)."
1042 :type 'number
1043 :group 'ps-print-horizontal)
bcc0d457 1044
e0af0d3e
RS
1045(defcustom ps-inter-column (/ (* 72 2.0) 2.54) ; 2 cm
1046 "*Horizontal space between columns in points (1/72 inch)."
1047 :type 'number
1048 :group 'ps-print-horizontal)
bcc0d457
RS
1049
1050;;; Vertical layout
1051
1052;; |--------|
1053;; | tm |
1054;; |--------|
1055;; | header |
1056;; |--------|
1057;; | ho |
1058;; |--------|
1059;; | text |
1060;; |--------|
1061;; | bm |
1062;; |--------|
1063
e0af0d3e
RS
1064(defcustom ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
1065 "*Bottom margin in points (1/72 inch)."
1066 :type 'number
1067 :group 'ps-print-vertical)
bcc0d457 1068
e0af0d3e
RS
1069(defcustom ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
1070 "*Top margin in points (1/72 inch)."
1071 :type 'number
1072 :group 'ps-print-vertical)
bcc0d457 1073
e0af0d3e
RS
1074(defcustom ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
1075 "*Vertical space in points (1/72 inch) between the main text and the header."
1076 :type 'number
1077 :group 'ps-print-vertical)
bcc0d457 1078
e0af0d3e 1079(defcustom ps-header-line-pad 0.15
bcc0d457 1080 "*Portion of a header title line height to insert between the header frame
e0af0d3e
RS
1081and the text it contains, both in the vertical and horizontal directions."
1082 :type 'number
1083 :group 'ps-print-vertical)
bcc0d457
RS
1084
1085;;; Header setup
12d89a2e 1086
e0af0d3e 1087(defcustom ps-print-header t
86c10ecb
RS
1088 "*Non-nil means print a header at the top of each page.
1089By default, the header displays the buffer name, page number, and, if
1090the buffer is visiting a file, the file's directory. Headers are
ae7f6761 1091customizable by changing variables `ps-left-header' and
e0af0d3e
RS
1092`ps-right-header'."
1093 :type 'boolean
1094 :group 'ps-print-header)
1095
1096(defcustom ps-print-header-frame t
1097 "*Non-nil means draw a gaudy frame around the header."
1098 :type 'boolean
1099 :group 'ps-print-header)
1100
1101(defcustom ps-header-lines 2
8bd22fcf 1102 "*Number of lines to display in page header, when generating PostScript."
e0af0d3e
RS
1103 :type 'integer
1104 :group 'ps-print-header)
bcc0d457
RS
1105(make-variable-buffer-local 'ps-header-lines)
1106
e0af0d3e 1107(defcustom ps-show-n-of-n t
00aa16af 1108 "*Non-nil means show page numbers as N/M, meaning page N of M.
8bd22fcf
KH
1109NOTE: page numbers are displayed as part of headers,
1110 see variable `ps-print-headers'."
e0af0d3e
RS
1111 :type 'boolean
1112 :group 'ps-print-header)
12d89a2e 1113
e0af0d3e 1114(defcustom ps-spool-duplex nil ; Not many people have duplex
bcc0d457
RS
1115 ; printers, so default to nil.
1116 "*Non-nil indicates spooling is for a two-sided printer.
1117For a duplex printer, the `ps-spool-*' commands will insert blank pages
1118as needed between print jobs so that the next buffer printed will
1119start on the right page. Also, if headers are turned on, the headers
1120will be reversed on duplex printers so that the page numbers fall to
e0af0d3e
RS
1121the left on even-numbered pages."
1122 :type 'boolean
1123 :group 'ps-print-header)
bcc0d457
RS
1124
1125;;; Fonts
1126
e0af0d3e 1127(defcustom ps-font-info-database
bcc0d457
RS
1128 '((Courier ; the family key
1129 "Courier" "Courier-Bold" "Courier-Oblique" "Courier-BoldOblique"
1130 10.0 10.55 6.0 6.0)
1131 (Helvetica ; the family key
1132 "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
1133 10.0 11.56 2.78 5.09243)
1134 (Times
1135 "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic"
1136 10.0 11.0 2.5 4.71432)
1137 (Palatino
1138 "Palatino-Roman" "Palatino-Bold" "Palatino-Italic" "Palatino-BoldItalic"
1139 10.0 12.1 2.5 5.08676)
1140 (Helvetica-Narrow
1141 "Helvetica-Narrow" "Helvetica-Narrow-Bold"
1142 "Helvetica-Narrow-Oblique" "Helvetica-Narrow-BoldOblique"
1143 10.0 11.56 2.2796 4.17579)
1144 (NewCenturySchlbk
1145 "NewCenturySchlbk-Roman" "NewCenturySchlbk-Bold"
1146 "NewCenturySchlbk-Italic" "NewCenturySchlbk-BoldItalic"
1147 10.0 12.15 2.78 5.31162)
1148 ;; got no bold for the next ones
1149 (AvantGarde-Book
1150 "AvantGarde-Book" "AvantGarde-Book"
1151 "AvantGarde-BookOblique" "AvantGarde-BookOblique"
1152 10.0 11.77 2.77 5.45189)
1153 (AvantGarde-Demi
1154 "AvantGarde-Demi" "AvantGarde-Demi"
1155 "AvantGarde-DemiOblique" "AvantGarde-DemiOblique"
1156 10.0 12.72 2.8 5.51351)
1157 (Bookman-Demi
1158 "Bookman-Demi" "Bookman-Demi"
1159 "Bookman-DemiItalic" "Bookman-DemiItalic"
1160 10.0 11.77 3.4 6.05946)
1161 (Bookman-Light
1162 "Bookman-Light" "Bookman-Light"
1163 "Bookman-LightItalic" "Bookman-LightItalic"
1164 10.0 11.79 3.2 5.67027)
1165 ;; got no bold and no italic for the next ones
1166 (Symbol
1167 "Symbol" "Symbol" "Symbol" "Symbol"
1168 10.0 13.03 2.5 3.24324)
1169 (Zapf-Dingbats
1170 "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats"
1171 10.0 9.63 2.78 2.78)
1172 (Zapf-Chancery-MediumItalic
1173 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
1174 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
1175 10.0 11.45 2.2 4.10811)
87a16a06 1176 )
bcc0d457
RS
1177 "*Font info database: font family (the key), name, bold, italic, bold-italic,
1178reference size, line height, space width, average character width.
1179To get the info for another specific font (say Helvetica), do the following:
1180- create a new buffer
1181- generate the PostScript image to a file (C-u M-x ps-print-buffer)
8bd22fcf 1182- open this file and delete the leading `%' (which is the PostScript
bcc0d457 1183 comment character) from the line
87a16a06 1184 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
bcc0d457 1185 to get the line
87a16a06 1186 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
bcc0d457 1187- add the values to `ps-font-info-database'.
e0af0d3e
RS
1188You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
1189 :type '(repeat (list :tag "Font Definition"
1190 (symbol :tag "Font")
1191 (string :tag "Name")
1192 (string :tag "Bold")
1193 (string :tag "Italic")
1194 (string :tag "Bold-Italic")
1195 (number :tag "Reference Size")
1196 (number :tag "Line Height")
1197 (number :tag "Space Width")
1198 (number :tag "Average Character Width")))
1199 :group 'ps-print-font)
1200
1201(defcustom ps-font-family 'Courier
8bd22fcf 1202 "Font family name for ordinary text, when generating PostScript."
e0af0d3e
RS
1203 :type 'symbol
1204 :group 'ps-print-font)
1205
1206(defcustom ps-font-size (if ps-landscape-mode 7 8.5)
8bd22fcf 1207 "Font size, in points, for ordinary text, when generating PostScript."
e0af0d3e
RS
1208 :type 'number
1209 :group 'ps-print-font)
1210
1211(defcustom ps-header-font-family 'Helvetica
8bd22fcf 1212 "Font family name for text in the header, when generating PostScript."
e0af0d3e
RS
1213 :type 'symbol
1214 :group 'ps-print-font)
1215
1216(defcustom ps-header-font-size (if ps-landscape-mode 10 12)
8bd22fcf 1217 "Font size, in points, for text in the header, when generating PostScript."
e0af0d3e
RS
1218 :type 'number
1219 :group 'ps-print-font)
1220
1221(defcustom ps-header-title-font-size (if ps-landscape-mode 12 14)
bcc0d457 1222 "Font size, in points, for the top line of text in the header,
8bd22fcf 1223when generating PostScript."
e0af0d3e
RS
1224 :type 'number
1225 :group 'ps-print-font)
bcc0d457
RS
1226
1227;;; Colors
1228
87a16a06
RS
1229;; Printing color requires x-color-values.
1230(defcustom ps-print-color-p (or (fboundp 'x-color-values) ; Emacs
857686a6
RS
1231 (fboundp 'color-instance-rgb-components))
1232 ; XEmacs
e0af0d3e
RS
1233 "*If non-nil, print the buffer's text in color."
1234 :type 'boolean
1235 :group 'ps-print-color)
12d89a2e 1236
e0af0d3e
RS
1237(defcustom ps-default-fg '(0.0 0.0 0.0)
1238 "*RGB values of the default foreground color. Defaults to black."
1239 :type '(list (number :tag "Red") (number :tag "Green") (number :tag "Blue"))
1240 :group 'ps-print-color)
12d89a2e 1241
e0af0d3e
RS
1242(defcustom ps-default-bg '(1.0 1.0 1.0)
1243 "*RGB values of the default background color. Defaults to white."
1244 :type '(list (number :tag "Red") (number :tag "Green") (number :tag "Blue"))
1245 :group 'ps-print-color)
12d89a2e 1246
e0af0d3e 1247(defcustom ps-auto-font-detect t
12d89a2e 1248 "*Non-nil means automatically detect bold/italic face attributes.
7f72c06f 1249If nil, we rely solely on the lists `ps-bold-faces', `ps-italic-faces',
e0af0d3e
RS
1250and `ps-underlined-faces'."
1251 :type 'boolean
1252 :group 'ps-print-font)
12d89a2e 1253
e0af0d3e 1254(defcustom ps-bold-faces
090be653
RS
1255 (unless ps-print-color-p
1256 '(font-lock-function-name-face
1257 font-lock-builtin-face
1258 font-lock-variable-name-face
1259 font-lock-keyword-face
1260 font-lock-warning-face))
86c10ecb 1261 "*A list of the \(non-bold\) faces that should be printed in bold font.
8bd22fcf 1262This applies to generating PostScript."
e0af0d3e
RS
1263 :type '(repeat face)
1264 :group 'ps-print-face)
12d89a2e 1265
e0af0d3e 1266(defcustom ps-italic-faces
090be653
RS
1267 (unless ps-print-color-p
1268 '(font-lock-variable-name-face
8bd22fcf 1269 font-lock-type-face
090be653
RS
1270 font-lock-string-face
1271 font-lock-comment-face
1272 font-lock-warning-face))
86c10ecb 1273 "*A list of the \(non-italic\) faces that should be printed in italic font.
8bd22fcf 1274This applies to generating PostScript."
e0af0d3e
RS
1275 :type '(repeat face)
1276 :group 'ps-print-face)
12d89a2e 1277
e0af0d3e 1278(defcustom ps-underlined-faces
090be653
RS
1279 (unless ps-print-color-p
1280 '(font-lock-function-name-face
883212ce 1281 font-lock-constant-face
090be653 1282 font-lock-warning-face))
86c10ecb 1283 "*A list of the \(non-underlined\) faces that should be printed underlined.
8bd22fcf 1284This applies to generating PostScript."
e0af0d3e
RS
1285 :type '(repeat face)
1286 :group 'ps-print-face)
12d89a2e 1287
e0af0d3e 1288(defcustom ps-left-header
12d89a2e 1289 (list 'ps-get-buffer-name 'ps-header-dirpart)
bcc0d457 1290 "*The items to display (each on a line) on the left part of the page header.
8bd22fcf 1291This applies to generating PostScript.
12d89a2e 1292
86c10ecb 1293The value should be a list of strings and symbols, each representing an
12d89a2e
RS
1294entry in the PostScript array HeaderLinesLeft.
1295
1296Strings are inserted unchanged into the array; those representing
1297PostScript string literals should be delimited with PostScript string
1298delimiters '(' and ')'.
1299
1300For symbols with bound functions, the function is called and should
1301return a string to be inserted into the array. For symbols with bound
1302values, the value should be a string to be inserted into the array.
1303In either case, function or variable, the string value has PostScript
e0af0d3e
RS
1304string delimiters added to it."
1305 :type '(repeat (choice string symbol))
a6c6e755 1306 :group 'ps-print-header)
12d89a2e
RS
1307(make-variable-buffer-local 'ps-left-header)
1308
e0af0d3e 1309(defcustom ps-right-header
090be653 1310 (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss)
bcc0d457 1311 "*The items to display (each on a line) on the right part of the page header.
8bd22fcf 1312This applies to generating PostScript.
12d89a2e 1313
86c10ecb 1314See the variable `ps-left-header' for a description of the format of
e0af0d3e
RS
1315this variable."
1316 :type '(repeat (choice string symbol))
a6c6e755 1317 :group 'ps-print-header)
12d89a2e 1318(make-variable-buffer-local 'ps-right-header)
ef2cbb24 1319
e0af0d3e
RS
1320(defcustom ps-razzle-dazzle t
1321 "*Non-nil means report progress while formatting buffer."
1322 :type 'boolean
1323 :group 'ps-print)
12d89a2e 1324
a18ed129 1325(defcustom ps-adobe-tag "%!PS-Adobe-3.0\n"
12d89a2e
RS
1326 "*Contains the header line identifying the output as PostScript.
1327By default, `ps-adobe-tag' contains the standard identifier. Some
a18ed129
RS
1328printers require slightly different versions of this line."
1329 :type 'string
1330 :group 'ps-print)
12d89a2e 1331
e0af0d3e 1332(defcustom ps-build-face-reference t
12d89a2e
RS
1333 "*Non-nil means build the reference face lists.
1334
1335Ps-print sets this value to nil after it builds its internal reference
1336lists of bold and italic faces. By settings its value back to t, you
1337can force ps-print to rebuild the lists the next time you invoke one
86c10ecb 1338of the ...-with-faces commands.
12d89a2e
RS
1339
1340You should set this value back to t after you change the attributes of
1341any face, or create new faces. Most users shouldn't have to worry
e0af0d3e
RS
1342about its setting, though."
1343 :type 'boolean
1344 :group 'ps-print-face)
12d89a2e 1345
e0af0d3e 1346(defcustom ps-always-build-face-reference nil
12d89a2e
RS
1347 "*Non-nil means always rebuild the reference face lists.
1348
1349If this variable is non-nil, ps-print will rebuild its internal
1350reference lists of bold and italic faces *every* time one of the
1351-with-faces commands is called. Most users shouldn't need to set this
e0af0d3e
RS
1352variable."
1353 :type 'boolean
1354 :group 'ps-print-face)
ef2cbb24
RS
1355
1356;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12d89a2e 1357;; User commands
ef2cbb24 1358
00aa16af 1359;;;###autoload
ef2cbb24 1360(defun ps-print-buffer (&optional filename)
12d89a2e 1361 "Generate and print a PostScript image of the buffer.
ef2cbb24 1362
86c10ecb 1363When called with a numeric prefix argument (C-u), prompts the user for
ef2cbb24
RS
1364the name of a file to save the PostScript image in, instead of sending
1365it to the printer.
1366
1367More specifically, the FILENAME argument is treated as follows: if it
1368is nil, send the image to the printer. If FILENAME is a string, save
1369the PostScript image in a file with that name. If FILENAME is a
12d89a2e 1370number, prompt the user for the name of the file to save in."
00aa16af 1371 (interactive (list (ps-print-preprint current-prefix-arg)))
87a16a06 1372 (ps-print-without-faces (point-min) (point-max) filename))
ef2cbb24
RS
1373
1374
00aa16af 1375;;;###autoload
ef2cbb24 1376(defun ps-print-buffer-with-faces (&optional filename)
12d89a2e 1377 "Generate and print a PostScript image of the buffer.
12d89a2e 1378Like `ps-print-buffer', but includes font, color, and underline
107e7c70
KH
1379information in the generated image. This command works only if you
1380are using a window system, so it has a way to determine color values."
00aa16af 1381 (interactive (list (ps-print-preprint current-prefix-arg)))
87a16a06 1382 (ps-print-with-faces (point-min) (point-max) filename))
ef2cbb24 1383
ef2cbb24 1384
00aa16af 1385;;;###autoload
ef2cbb24 1386(defun ps-print-region (from to &optional filename)
12d89a2e 1387 "Generate and print a PostScript image of the region.
12d89a2e 1388Like `ps-print-buffer', but prints just the current region."
00aa16af 1389 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
a18ed129 1390 (ps-print-without-faces from to filename t))
ef2cbb24 1391
ef2cbb24 1392
00aa16af 1393;;;###autoload
ef2cbb24 1394(defun ps-print-region-with-faces (from to &optional filename)
12d89a2e 1395 "Generate and print a PostScript image of the region.
12d89a2e 1396Like `ps-print-region', but includes font, color, and underline
107e7c70
KH
1397information in the generated image. This command works only if you
1398are using a window system, so it has a way to determine color values."
00aa16af 1399 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
a18ed129 1400 (ps-print-with-faces from to filename t))
ef2cbb24 1401
ef2cbb24 1402
00aa16af 1403;;;###autoload
ef2cbb24 1404(defun ps-spool-buffer ()
12d89a2e 1405 "Generate and spool a PostScript image of the buffer.
12d89a2e
RS
1406Like `ps-print-buffer' except that the PostScript image is saved in a
1407local buffer to be sent to the printer later.
ef2cbb24 1408
12d89a2e 1409Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 1410 (interactive)
87a16a06 1411 (ps-spool-without-faces (point-min) (point-max)))
ef2cbb24 1412
ef2cbb24 1413
00aa16af 1414;;;###autoload
ef2cbb24 1415(defun ps-spool-buffer-with-faces ()
12d89a2e 1416 "Generate and spool a PostScript image of the buffer.
12d89a2e 1417Like `ps-spool-buffer', but includes font, color, and underline
107e7c70 1418information in the generated image. This command works only if you
1cd7962f 1419are using a window system, so it has a way to determine color values.
ef2cbb24 1420
12d89a2e 1421Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 1422 (interactive)
87a16a06 1423 (ps-spool-with-faces (point-min) (point-max)))
ef2cbb24 1424
ef2cbb24 1425
00aa16af 1426;;;###autoload
ef2cbb24 1427(defun ps-spool-region (from to)
12d89a2e 1428 "Generate a PostScript image of the region and spool locally.
12d89a2e 1429Like `ps-spool-buffer', but spools just the current region.
ef2cbb24 1430
12d89a2e 1431Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 1432 (interactive "r")
a18ed129 1433 (ps-spool-without-faces from to t))
ef2cbb24 1434
ef2cbb24 1435
00aa16af 1436;;;###autoload
ef2cbb24 1437(defun ps-spool-region-with-faces (from to)
12d89a2e 1438 "Generate a PostScript image of the region and spool locally.
12d89a2e 1439Like `ps-spool-region', but includes font, color, and underline
107e7c70 1440information in the generated image. This command works only if you
1cd7962f 1441are using a window system, so it has a way to determine color values.
ef2cbb24 1442
12d89a2e 1443Use the command `ps-despool' to send the spooled images to the printer."
ef2cbb24 1444 (interactive "r")
a18ed129 1445 (ps-spool-with-faces from to t))
ef2cbb24 1446
00aa16af 1447;;;###autoload
ef2cbb24
RS
1448(defun ps-despool (&optional filename)
1449 "Send the spooled PostScript to the printer.
1450
1451When called with a numeric prefix argument (C-u), prompt the user for
1452the name of a file to save the spooled PostScript in, instead of sending
1453it to the printer.
1454
1455More specifically, the FILENAME argument is treated as follows: if it
1456is nil, send the image to the printer. If FILENAME is a string, save
1457the PostScript image in a file with that name. If FILENAME is a
1458number, prompt the user for the name of the file to save in."
00aa16af
RS
1459 (interactive (list (ps-print-preprint current-prefix-arg)))
1460 (ps-do-despool filename))
12d89a2e 1461
bcc0d457
RS
1462;;;###autoload
1463(defun ps-line-lengths ()
06fb6aab 1464 "Display the correspondence between a line length and a font size,
bcc0d457
RS
1465using the current ps-print setup.
1466Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1467 (interactive)
1468 (ps-line-lengths-internal))
1469
1470;;;###autoload
1471(defun ps-nb-pages-buffer (nb-lines)
06fb6aab
RS
1472 "Display number of pages to print this buffer, for various font heights.
1473The table depends on the current ps-print setup."
bcc0d457
RS
1474 (interactive (list (count-lines (point-min) (point-max))))
1475 (ps-nb-pages nb-lines))
1476
1477;;;###autoload
1478(defun ps-nb-pages-region (nb-lines)
06fb6aab
RS
1479 "Display number of pages to print the region, for various font heights.
1480The table depends on the current ps-print setup."
bcc0d457
RS
1481 (interactive (list (count-lines (mark) (point))))
1482 (ps-nb-pages nb-lines))
1483
1484;;;###autoload
1485(defun ps-setup ()
06fb6aab 1486 "Return the current setup."
a18ed129
RS
1487 (format
1488 "
1489\(setq ps-print-color-p %s
bcc0d457
RS
1490 ps-lpr-command \"%s\"
1491 ps-lpr-switches %s
1492
8bd22fcf
KH
1493 ps-paper-type '%s
1494 ps-landscape-mode %s
1495 ps-number-of-columns %s
bcc0d457 1496
8bd22fcf 1497 ps-zebra-stripes %s
01961237 1498 ps-zebra-stripe-height %s
8bd22fcf 1499 ps-line-number %s
a18ed129 1500
857686a6
RS
1501 ps-print-control-characters %s
1502
a18ed129
RS
1503 ps-print-background-image %s
1504
1505 ps-print-background-text %s
1506
1507 ps-left-margin %s
1508 ps-right-margin %s
1509 ps-inter-column %s
1510 ps-bottom-margin %s
1511 ps-top-margin %s
1512 ps-header-offset %s
bcc0d457
RS
1513 ps-header-line-pad %s
1514 ps-print-header %s
1515 ps-print-header-frame %s
1516 ps-header-lines %s
1517 ps-show-n-of-n %s
1518 ps-spool-duplex %s
1519
a18ed129
RS
1520 ps-font-family '%s
1521 ps-font-size %s
1522 ps-header-font-family '%s
1523 ps-header-font-size %s
1524 ps-header-title-font-size %s)
bcc0d457 1525"
a18ed129
RS
1526 ps-print-color-p
1527 ps-lpr-command
1528 ps-lpr-switches
1529 ps-paper-type
1530 ps-landscape-mode
1531 ps-number-of-columns
01961237
RS
1532 ps-zebra-stripes
1533 ps-zebra-stripe-height
a18ed129 1534 ps-line-number
857686a6 1535 ps-print-control-characters
a18ed129
RS
1536 ps-print-background-image
1537 ps-print-background-text
1538 ps-left-margin
1539 ps-right-margin
1540 ps-inter-column
1541 ps-bottom-margin
1542 ps-top-margin
1543 ps-header-offset
1544 ps-header-line-pad
1545 ps-print-header
1546 ps-print-header-frame
1547 ps-header-lines
1548 ps-show-n-of-n
1549 ps-spool-duplex
1550 ps-font-family
1551 ps-font-size
1552 ps-header-font-family
1553 ps-header-font-size
1554 ps-header-title-font-size))
bcc0d457 1555
12d89a2e
RS
1556;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1557;; Utility functions and variables:
1558
6770a60f
RS
1559(defvar ps-print-emacs-type
1560 (cond ((string-match "XEmacs" emacs-version) 'xemacs)
1561 ((string-match "Lucid" emacs-version) 'lucid)
1562 ((string-match "Epoch" emacs-version) 'epoch)
1563 (t 'emacs)))
1564
1565(if (or (eq ps-print-emacs-type 'lucid)
1566 (eq ps-print-emacs-type 'xemacs))
043620f4
KH
1567 (if (< emacs-minor-version 12)
1568 (setq ps-print-color-p nil))
12d89a2e
RS
1569 (require 'faces)) ; face-font, face-underline-p,
1570 ; x-font-regexp
1571
857686a6
RS
1572;; Return t if the device (which can be changed during an emacs session)
1573;; can handle colors.
1574;; This is function is not yet implemented for GNU emacs.
1575(defun ps-color-device ()
1576 (if (and (eq ps-print-emacs-type 'xemacs)
1577 (>= emacs-minor-version 12))
1578 (eq (device-class) 'color)
1579 t))
1580
12d89a2e
RS
1581(require 'time-stamp)
1582
bcc0d457 1583(defvar ps-font nil
8bd22fcf 1584 "Font family name for ordinary text, when generating PostScript.")
bcc0d457
RS
1585
1586(defvar ps-font-bold nil
8bd22fcf 1587 "Font family name for bold text, when generating PostScript.")
bcc0d457
RS
1588
1589(defvar ps-font-italic nil
8bd22fcf 1590 "Font family name for italic text, when generating PostScript.")
bcc0d457
RS
1591
1592(defvar ps-font-bold-italic nil
8bd22fcf 1593 "Font family name for bold italic text, when generating PostScript.")
bcc0d457
RS
1594
1595(defvar ps-avg-char-width nil
8bd22fcf 1596 "The average width, in points, of a character, for generating PostScript.
bcc0d457
RS
1597This is the value that ps-print uses to determine the length,
1598x-dimension, of the text it has printed, and thus affects the point at
1599which long lines wrap around.")
1600
1601(defvar ps-space-width nil
8bd22fcf 1602 "The width of a space character, for generating PostScript.
bcc0d457
RS
1603This value is used in expanding tab characters.")
1604
1605(defvar ps-line-height nil
8bd22fcf 1606 "The height of a line, for generating PostScript.
bcc0d457
RS
1607This is the value that ps-print uses to determine the height,
1608y-dimension, of the lines of text it has printed, and thus affects the
1609point at which page-breaks are placed.
1610The line-height is *not* the same as the point size of the font.")
1611
1612(defvar ps-print-prologue-1
1613 "% ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4:
12d89a2e 1614/ISOLatin1Encoding where { pop } {
bcc0d457
RS
1615% -- The ISO Latin-1 encoding vector isn't known, so define it.
1616% -- The first half is the same as the standard encoding,
1617% -- except for minus instead of hyphen at code 055.
12d89a2e
RS
1618/ISOLatin1Encoding
1619StandardEncoding 0 45 getinterval aload pop
1620 /minus
1621StandardEncoding 46 82 getinterval aload pop
1622%*** NOTE: the following are missing in the Adobe documentation,
1623%*** but appear in the displayed table:
1624%*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240.
bcc0d457 1625% 0200 (128)
12d89a2e
RS
1626 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
1627 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
1628 /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent
1629 /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron
bcc0d457 1630% 0240 (160)
12d89a2e
RS
1631 /space /exclamdown /cent /sterling
1632 /currency /yen /brokenbar /section
1633 /dieresis /copyright /ordfeminine /guillemotleft
1634 /logicalnot /hyphen /registered /macron
1635 /degree /plusminus /twosuperior /threesuperior
1636 /acute /mu /paragraph /periodcentered
1637 /cedilla /onesuperior /ordmasculine /guillemotright
1638 /onequarter /onehalf /threequarters /questiondown
bcc0d457 1639% 0300 (192)
12d89a2e
RS
1640 /Agrave /Aacute /Acircumflex /Atilde
1641 /Adieresis /Aring /AE /Ccedilla
1642 /Egrave /Eacute /Ecircumflex /Edieresis
1643 /Igrave /Iacute /Icircumflex /Idieresis
1644 /Eth /Ntilde /Ograve /Oacute
1645 /Ocircumflex /Otilde /Odieresis /multiply
1646 /Oslash /Ugrave /Uacute /Ucircumflex
1647 /Udieresis /Yacute /Thorn /germandbls
bcc0d457 1648% 0340 (224)
12d89a2e
RS
1649 /agrave /aacute /acircumflex /atilde
1650 /adieresis /aring /ae /ccedilla
1651 /egrave /eacute /ecircumflex /edieresis
1652 /igrave /iacute /icircumflex /idieresis
1653 /eth /ntilde /ograve /oacute
1654 /ocircumflex /otilde /odieresis /divide
1655 /oslash /ugrave /uacute /ucircumflex
1656 /udieresis /yacute /thorn /ydieresis
1657256 packedarray def
1658} ifelse
1659
1660/reencodeFontISO { %def
1661 dup
87a16a06 1662 length 12 add dict % Make a new font (a new dict the same size
bcc0d457 1663 % as the old one) with room for our new symbols.
12d89a2e 1664
bcc0d457 1665 begin % Make the new font the current dictionary.
12d89a2e
RS
1666
1667
1668 { 1 index /FID ne
1669 { def } { pop pop } ifelse
bcc0d457
RS
1670 } forall % Copy each of the symbols from the old dictionary
1671 % to the new one except for the font ID.
12d89a2e
RS
1672
1673 /Encoding ISOLatin1Encoding def % Override the encoding with
1674 % the ISOLatin1 encoding.
1675
1676 % Use the font's bounding box to determine the ascent, descent,
1677 % and overall height; don't forget that these values have to be
1678 % transformed using the font's matrix.
bcc0d457
RS
1679
1680% ^ (x2 y2)
1681% | |
1682% | v
1683% | +----+ - -
1684% | | | ^
1685% | | | | Ascent (usually > 0)
1686% | | | |
1687% (0 0) -> +--+----+-------->
1688% | | |
1689% | | v Descent (usually < 0)
1690% (x1 y1) --> +----+ - -
1691
1692 FontBBox % -- x1 y1 x2 y2
1693 FontMatrix transform /Ascent exch def pop
12d89a2e 1694 FontMatrix transform /Descent exch def pop
bcc0d457 1695 /FontHeight Ascent Descent sub def % use `sub' because descent < 0
12d89a2e 1696
bcc0d457 1697 % Define these in case they're not in the FontInfo
87a16a06
RS
1698 % (also, here they're easier to get to).
1699 /UnderlinePosition Descent 0.70 mul def
1700 /OverlinePosition Descent UnderlinePosition sub Ascent add def
1701 /StrikeoutPosition Ascent 0.30 mul def
1702 /LineThickness 0 50 FontMatrix transform exch pop def
1703 /Xshadow 0 80 FontMatrix transform exch pop def
1704 /Yshadow 0 -90 FontMatrix transform exch pop def
1705 /SpaceBackground Descent neg UnderlinePosition add def
1706 /XBox Descent neg def
1707 /YBox LineThickness 0.7 mul def
12d89a2e 1708
bcc0d457
RS
1709 currentdict % Leave the new font on the stack
1710 end % Stop using the font as the current dictionary.
1711 definefont % Put the font into the font dictionary
1712 pop % Discard the returned font.
12d89a2e 1713} bind def
ef2cbb24 1714
bcc0d457 1715/DefFont { % Font definition
12d89a2e
RS
1716 findfont exch scalefont reencodeFontISO
1717} def
1718
bcc0d457 1719/F { % Font selection
12d89a2e 1720 findfont
87a16a06
RS
1721 dup /Ascent get /Ascent exch def
1722 dup /Descent get /Descent exch def
1723 dup /FontHeight get /FontHeight exch def
1724 dup /UnderlinePosition get /UnderlinePosition exch def
1725 dup /OverlinePosition get /OverlinePosition exch def
1726 dup /StrikeoutPosition get /StrikeoutPosition exch def
1727 dup /LineThickness get /LineThickness exch def
1728 dup /Xshadow get /Xshadow exch def
1729 dup /Yshadow get /Yshadow exch def
1730 dup /SpaceBackground get /SpaceBackground exch def
1731 dup /XBox get /XBox exch def
1732 dup /YBox get /YBox exch def
12d89a2e
RS
1733 setfont
1734} def
1735
1736/FG /setrgbcolor load def
1737
1738/bg false def
1739/BG {
1740 dup /bg exch def
87a16a06
RS
1741 {mark 4 1 roll ]}
1742 {[ 1.0 1.0 1.0 ]}
1743 ifelse
1744 /bgcolor exch def
12d89a2e
RS
1745} def
1746
bcc0d457
RS
1747% B width C
1748% +-----------+
1749% | Ascent (usually > 0)
1750% A + +
1751% | Descent (usually < 0)
1752% +-----------+
1753% E width D
1754
12d89a2e 1755/dobackground { % width --
bcc0d457 1756 currentpoint % -- width x y
12d89a2e
RS
1757 gsave
1758 newpath
bcc0d457
RS
1759 moveto % A (x y)
1760 0 Ascent rmoveto % B
1761 dup 0 rlineto % C
1762 0 Descent Ascent sub rlineto % D
1763 neg 0 rlineto % E
12d89a2e
RS
1764 closepath
1765 bgcolor aload pop setrgbcolor
1766 fill
1767 grestore
1768} def
1769
bcc0d457
RS
1770/eolbg { % dobackground until right margin
1771 PrintWidth % -- x-eol
1772 currentpoint pop % -- cur-x
1773 sub % -- width until eol
1774 dobackground
12d89a2e
RS
1775} def
1776
87a16a06 1777/PLN {PrintLineNumber {doLineNumber}if} def
12d89a2e
RS
1778
1779/SL { % Soft Linefeed
1780 bg { eolbg } if
bcc0d457 1781 0 currentpoint exch pop LineHeight sub moveto
12d89a2e
RS
1782} def
1783
87a16a06 1784/HL {SL PLN} def % Hard Linefeed
12d89a2e
RS
1785
1786% Some debug
1787/dcp { currentpoint exch 40 string cvs print (, ) print = } def
87a16a06 1788/dp { print 2 copy exch 40 string cvs print (, ) print = } def
12d89a2e
RS
1789
1790/W {
bcc0d457
RS
1791 ( ) stringwidth % Get the width of a space in the current font.
1792 pop % Discard the Y component.
1793 mul % Multiply the width of a space
1794 % by the number of spaces to plot
12d89a2e
RS
1795 bg { dup dobackground } if
1796 0 rmoveto
87a16a06
RS
1797} def
1798
1799/Effect 0 def
1800/EF {/Effect exch def} def
1801
1802% stack: string |- --
1803% effect: 1 - underline 2 - strikeout 4 - overline
1804% 8 - shadow 16 - box 32 - outline
1805/S {
1806 /xx currentpoint dup Descent add /yy exch def
1807 Ascent add /YY exch def def
1808 dup stringwidth pop xx add /XX exch def
1809 Effect 8 and 0 ne {
1810 /yy yy Yshadow add def
1811 /XX XX Xshadow add def
1812 } if
1813 bg {
1814 true
1815 Effect 16 and 0 ne
1816 {SpaceBackground doBox}
1817 {xx yy XX YY doRect}
1818 ifelse
1819 } if % background
1820 Effect 16 and 0 ne {false 0 doBox}if % box
1821 Effect 8 and 0 ne {dup doShadow}if % shadow
1822 Effect 32 and 0 ne
1823 {true doOutline} % outline
1824 {show} % normal text
1825 ifelse
1826 Effect 1 and 0 ne {UnderlinePosition Hline}if % underline
1827 Effect 2 and 0 ne {StrikeoutPosition Hline}if % strikeout
1828 Effect 4 and 0 ne {OverlinePosition Hline}if % overline
1829} bind def
1830
1831% stack: position |- --
1832/Hline {
1833 currentpoint exch pop add dup
1834 gsave
1835 newpath
1836 xx exch moveto
1837 XX exch lineto
1838 closepath
1839 LineThickness setlinewidth stroke
1840 grestore
1841} bind def
1842
1843% stack: fill-or-not delta |- --
1844/doBox {
1845 /dd exch def
1846 xx XBox sub dd sub yy YBox sub dd sub
1847 XX XBox add dd add YY YBox add dd add
1848 doRect
1849} bind def
1850
1851% stack: fill-or-not lower-x lower-y upper-x upper-y |- --
1852/doRect {
1853 /rYY exch def
1854 /rXX exch def
1855 /ryy exch def
1856 /rxx exch def
1857 gsave
1858 newpath
1859 rXX rYY moveto
1860 rxx rYY lineto
1861 rxx ryy lineto
1862 rXX ryy lineto
1863 closepath
1864 % top of stack: fill-or-not
1865 {FillBgColor}
1866 {LineThickness setlinewidth stroke}
1867 ifelse
1868 grestore
1869} bind def
1870
1871% stack: string |- --
1872/doShadow {
1873 gsave
1874 Xshadow Yshadow rmoveto
1875 false doOutline
1876 grestore
1877} bind def
1878
1879/st 1 string def
1880
1881% stack: string fill-or-not |- --
1882/doOutline {
1883 /-fillp- exch def
1884 /-ox- currentpoint /-oy- exch def def
1885 gsave
1886 LineThickness setlinewidth
1887 {
1888 st 0 3 -1 roll put
1889 st dup true charpath
1890 -fillp- {gsave FillBgColor grestore}if
1891 stroke stringwidth
1892 -oy- add /-oy- exch def
1893 -ox- add /-ox- exch def
1894 -ox- -oy- moveto
1895 } forall
1896 grestore
1897 -ox- -oy- moveto
1898} bind def
1899
1900% stack: --
1901/FillBgColor {bgcolor aload pop setrgbcolor fill} bind def
1902
1903/L0 6 /Times-Italic DefFont
1904
1905% stack: --
1906/doLineNumber {
1907 currentfont
1908 gsave
1909 0.0 0.0 0.0 setrgbcolor
1910 /L0 findfont setfont
1911 LineNumber Lines ge
1912 {(end )}
1913 {LineNumber 6 string cvs ( ) strcat}
1914 ifelse
1915 dup stringwidth pop neg 0 rmoveto
1916 show
1917 grestore
1918 setfont
1919 /LineNumber LineNumber 1 add def
1920} def
1921
1922% stack: --
1923/printZebra {
1924 gsave
1925 0.985 setgray
857686a6 1926 /double-zebra ZebraHeight ZebraHeight add def
87a16a06
RS
1927 /yiter double-zebra LineHeight mul neg def
1928 /xiter PrintWidth InterColumn add def
1929 NumberOfColumns {LinesPerColumn doColumnZebra xiter 0 rmoveto}repeat
1930 grestore
1931} def
1932
1933% stack: lines-per-column |- --
1934/doColumnZebra {
1935 gsave
857686a6 1936 dup double-zebra idiv {ZebraHeight doZebra 0 yiter rmoveto}repeat
87a16a06 1937 double-zebra mod
857686a6 1938 dup 0 le {pop}{dup ZebraHeight gt {pop ZebraHeight}if doZebra}ifelse
87a16a06
RS
1939 grestore
1940} def
1941
1942% stack: zebra-height (in lines) |- --
1943/doZebra {
1944 /zh exch 0.05 sub LineHeight mul def
1945 gsave
1946 0 LineHeight 0.65 mul rmoveto
1947 PrintWidth 0 rlineto
1948 0 zh neg rlineto
1949 PrintWidth neg 0 rlineto
1950 0 zh rlineto
1951 fill
1952 grestore
1953} def
1954
1955% tx ty rotation xscale yscale xpos ypos BeginBackImage
1956/BeginBackImage {
1957 /-save-image- save def
1958 /showpage {}def
1959 translate
1960 scale
1961 rotate
1962 translate
1963} def
1964
1965/EndBackImage {
1966 -save-image- restore
1967} def
1968
1969% string fontsize fontname rotation gray xpos ypos ShowBackText
1970/ShowBackText {
1971 gsave
1972 translate
1973 setgray
1974 rotate
1975 findfont exch dup /-offset- exch -0.25 mul def scalefont setfont
1976 0 -offset- moveto
1977 /-saveLineThickness- LineThickness def
1978 /LineThickness 1 def
1979 false doOutline
1980 /LineThickness -saveLineThickness- def
1981 grestore
12d89a2e
RS
1982} def
1983
bcc0d457
RS
1984/BeginDoc {
1985 % ---- save the state of the document (useful for ghostscript!)
1986 /docState save def
1987 % ---- [jack] Kludge: my ghostscript window is 21x27.7 instead of 21x29.7
1988 /JackGhostscript where {
1989 pop 1 27.7 29.7 div scale
1990 } if
1991 LandscapeMode {
1992 % ---- translate to bottom-right corner of Portrait page
1993 LandscapePageHeight 0 translate
1994 90 rotate
1995 } if
1996 /ColumnWidth PrintWidth InterColumn add def
1997 % ---- translate to lower left corner of TEXT
1998 LeftMargin BottomMargin translate
1999 % ---- define where printing will start
2000 /f0 F % this installs Ascent
2001 /PrintStartY PrintHeight Ascent sub def
2002 /ColumnIndex 1 def
2003} def
2004
2005/EndDoc {
2006 % ---- on last page but not last column, spit out the page
2007 ColumnIndex 1 eq not { showpage } if
2008 % ---- restore the state of the document (useful for ghostscript!)
2009 docState restore
2010} def
2011
12d89a2e 2012/BeginDSCPage {
bcc0d457 2013 % ---- when 1st column, save the state of the page
a18ed129 2014 ColumnIndex 1 eq { /pageState save def } if
bcc0d457
RS
2015 % ---- save the state of the column
2016 /columnState save def
12d89a2e
RS
2017} def
2018
2019/BeginPage {
a18ed129
RS
2020 % ---- when 1st column, print all background effects
2021 ColumnIndex 1 eq {
2022 0 PrintStartY moveto % move to where printing will start
2023 Zebra {printZebra}if
2024 printGlobalBackground
2025 printLocalBackground
2026 } if
12d89a2e
RS
2027 PrintHeader {
2028 PrintHeaderFrame { HeaderFrame } if
2029 HeaderText
2030 } if
bcc0d457 2031 0 PrintStartY moveto % move to where printing will start
87a16a06 2032 PLN
12d89a2e
RS
2033} def
2034
2035/EndPage {
2036 bg { eolbg } if
12d89a2e
RS
2037} def
2038
2039/EndDSCPage {
bcc0d457
RS
2040 ColumnIndex NumberOfColumns eq {
2041 % ---- on last column, spit out the page
2042 showpage
2043 % ---- restore the state of the page
2044 pageState restore
2045 /ColumnIndex 1 def
2046 } { % else
2047 % ---- restore the state of the current column
2048 columnState restore
2049 % ---- and translate to the next column
2050 ColumnWidth 0 translate
2051 /ColumnIndex ColumnIndex 1 add def
2052 } ifelse
12d89a2e
RS
2053} def
2054
bcc0d457 2055/SetHeaderLines { % nb-lines --
12d89a2e 2056 /HeaderLines exch def
bcc0d457
RS
2057 % ---- bottom up
2058 HeaderPad
2059 HeaderLines 1 sub HeaderLineHeight mul add
2060 HeaderTitleLineHeight add
2061 HeaderPad add
2062 /HeaderHeight exch def
12d89a2e
RS
2063} def
2064
bcc0d457
RS
2065% |---------|
2066% | tm |
2067% |---------|
2068% | header |
2069% |-+-------| <-- (x y)
2070% | ho |
2071% |---------|
2072% | text |
2073% |-+-------| <-- (0 0)
2074% | bm |
2075% |---------|
2076
2077/HeaderFrameStart { % -- x y
2078 0 PrintHeight HeaderOffset add
12d89a2e
RS
2079} def
2080
2081/HeaderFramePath {
bcc0d457
RS
2082 PrintWidth 0 rlineto
2083 0 HeaderHeight rlineto
2084 PrintWidth neg 0 rlineto
2085 0 HeaderHeight neg rlineto
12d89a2e
RS
2086} def
2087
2088/HeaderFrame {
2089 gsave
2090 0.4 setlinewidth
bcc0d457 2091 % ---- fill a black rectangle (the shadow of the next one)
12d89a2e
RS
2092 HeaderFrameStart moveto
2093 1 -1 rmoveto
2094 HeaderFramePath
2095 0 setgray fill
bcc0d457 2096 % ---- do the next rectangle ...
12d89a2e
RS
2097 HeaderFrameStart moveto
2098 HeaderFramePath
bcc0d457
RS
2099 gsave 0.9 setgray fill grestore % filled with grey
2100 gsave 0 setgray stroke grestore % drawn with black
12d89a2e
RS
2101 grestore
2102} def
2103
2104/HeaderStart {
2105 HeaderFrameStart
bcc0d457
RS
2106 exch HeaderPad add exch % horizontal pad
2107 % ---- bottom up
2108 HeaderPad add % vertical pad
2109 HeaderDescent sub
2110 HeaderLineHeight HeaderLines 1 sub mul add
12d89a2e
RS
2111} def
2112
2113/strcat {
2114 dup length 3 -1 roll dup length dup 4 -1 roll add string dup
2115 0 5 -1 roll putinterval
2116 dup 4 2 roll exch putinterval
2117} def
2118
2119/pagenumberstring {
2120 PageNumber 32 string cvs
2121 ShowNofN {
2122 (/) strcat
2123 PageCount 32 string cvs strcat
2124 } if
2125} def
2126
2127/HeaderText {
2128 HeaderStart moveto
2129
bcc0d457
RS
2130 HeaderLinesRight HeaderLinesLeft % -- rightLines leftLines
2131
2132 % ---- hack: `PN 1 and' == `PN 2 modulo'
2133
2134 % ---- if duplex and even page number, then exchange left and right
12d89a2e
RS
2135 Duplex PageNumber 1 and 0 eq and { exch } if
2136
bcc0d457 2137 { % ---- process the left lines
12d89a2e
RS
2138 aload pop
2139 exch F
2140 gsave
2141 dup xcheck { exec } if
2142 show
2143 grestore
2144 0 HeaderLineHeight neg rmoveto
2145 } forall
2146
2147 HeaderStart moveto
2148
bcc0d457 2149 { % ---- process the right lines
12d89a2e
RS
2150 aload pop
2151 exch F
2152 gsave
2153 dup xcheck { exec } if
2154 dup stringwidth pop
2155 PrintWidth exch sub HeaderPad 2 mul sub 0 rmoveto
2156 show
2157 grestore
2158 0 HeaderLineHeight neg rmoveto
2159 } forall
2160} def
2161
2162/ReportFontInfo {
2163 2 copy
bcc0d457 2164 /t0 3 1 roll DefFont
12d89a2e 2165 /t0 F
00aa16af 2166 /lh FontHeight def
12d89a2e
RS
2167 /sw ( ) stringwidth pop def
2168 /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch
2169 stringwidth pop exch div def
bcc0d457 2170 /t1 12 /Helvetica-Oblique DefFont
12d89a2e 2171 /t1 F
12d89a2e
RS
2172 gsave
2173 (For ) show
2174 128 string cvs show
2175 ( ) show
2176 32 string cvs show
2177 ( point, the line height is ) show
2178 lh 32 string cvs show
2179 (, the space width is ) show
2180 sw 32 string cvs show
2181 (,) show
2182 grestore
00aa16af 2183 0 FontHeight neg rmoveto
bcc0d457
RS
2184 gsave
2185 (and a crude estimate of average character width is ) show
2186 aw 32 string cvs show
2187 (.) show
2188 grestore
2189 0 FontHeight neg rmoveto
2190} def
2191
2192/cm { % cm to point
2193 72 mul 2.54 div
2194} def
2195
2196/ReportAllFontInfo {
2197 FontDirectory
2198 { % key = font name value = font dictionary
2199 pop 10 exch ReportFontInfo
2200 } forall
12d89a2e
RS
2201} def
2202
bcc0d457
RS
2203% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage
2204% 3 cm 20 cm moveto ReportAllFontInfo showpage
2205
2206")
2207
2208(defvar ps-print-prologue-2
2209 "
2210% ---- These lines must be kept together because...
2211
2212/h0 F
2213/HeaderTitleLineHeight FontHeight def
2214
2215/h1 F
2216/HeaderLineHeight FontHeight def
2217/HeaderDescent Descent def
2218
2219% ---- ...because `F' has a side-effect on `FontHeight' and `Descent'
2220
12d89a2e
RS
2221")
2222
2223;; Start Editing Here:
ef2cbb24 2224
12d89a2e
RS
2225(defvar ps-source-buffer nil)
2226(defvar ps-spool-buffer-name "*PostScript*")
2227(defvar ps-spool-buffer nil)
ef2cbb24 2228
12d89a2e
RS
2229(defvar ps-output-head nil)
2230(defvar ps-output-tail nil)
ef2cbb24 2231
12d89a2e 2232(defvar ps-page-count 0)
87a16a06
RS
2233(defvar ps-showline-count 1)
2234
857686a6
RS
2235(defvar ps-control-or-escape-regexp nil)
2236
87a16a06
RS
2237(defvar ps-background-pages nil)
2238(defvar ps-background-all-pages nil)
2239(defvar ps-background-text-count 0)
2240(defvar ps-background-image-count 0)
ef2cbb24 2241
12d89a2e 2242(defvar ps-current-font 0)
12d89a2e
RS
2243(defvar ps-default-color (if ps-print-color-p ps-default-fg)) ; black
2244(defvar ps-current-color ps-default-color)
2245(defvar ps-current-bg nil)
2246
2247(defvar ps-razchunk 0)
2248
bcc0d457
RS
2249(defvar ps-color-format
2250 (if (eq ps-print-emacs-type 'emacs)
12d89a2e 2251
bcc0d457
RS
2252 ;;Emacs understands the %f format; we'll
2253 ;;use it to limit color RGB values to
2254 ;;three decimals to cut down some on the
2255 ;;size of the PostScript output.
2256 "%0.3f %0.3f %0.3f"
12d89a2e 2257
bcc0d457
RS
2258 ;; Lucid emacsen will have to make do with
2259 ;; %s (princ) for floats.
2260 "%s %s %s"))
12d89a2e
RS
2261
2262;; These values determine how much print-height to deduct when headers
2263;; are turned on. This is a pretty clumsy way of handling it, but
2264;; it'll do for now.
12d89a2e 2265
87a16a06
RS
2266(defvar ps-header-font nil)
2267(defvar ps-header-title-font nil)
12d89a2e 2268
87a16a06
RS
2269(defvar ps-header-line-height nil)
2270(defvar ps-header-title-line-height nil)
bcc0d457
RS
2271(defvar ps-header-pad 0
2272 "Vertical and horizontal space in points (1/72 inch) between the header frame
2273and the text it contains.")
12d89a2e 2274
bcc0d457 2275;; Define accessors to the dimensions list.
12d89a2e 2276
bcc0d457
RS
2277(defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims))
2278(defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
12d89a2e 2279
87a16a06 2280(defvar ps-landscape-page-height nil)
12d89a2e 2281
12d89a2e
RS
2282(defvar ps-print-width nil)
2283(defvar ps-print-height nil)
2284
8bd22fcf
KH
2285(defvar ps-height-remaining nil)
2286(defvar ps-width-remaining nil)
12d89a2e 2287
bcc0d457
RS
2288(defvar ps-print-color-scale nil)
2289
87a16a06
RS
2290\f
2291;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2292;; Internal Variables
2293
2294
2295(defvar ps-print-face-extension-alist nil
a18ed129 2296 "Alist of symbolic faces *WITH* extension features (box, outline, etc).
87a16a06
RS
2297An element of this list has the following form:
2298
2299 (FACE . [BITS FG BG])
2300
2301 FACE is a symbol denoting a face name
2302 BITS is a bit vector, where each bit correspond
2303 to a feature (bold, underline, etc)
2304 (see documentation for `ps-print-face-map-alist')
2305 FG foreground color (string or nil)
2306 BG background color (string or nil)
2307
a18ed129
RS
2308Don't change this list directly; instead,
2309use `ps-extend-face' and `ps-extend-face-list'.
2310See documentation for `ps-extend-face' for valid extension symbol.")
2311
2312
2313(defvar ps-print-face-alist nil
2314 "Alist of symbolic faces *WITHOUT* extension features (box, outline, etc).
2315
2316An element of this list has the same form as an element of
2317`ps-print-face-extension-alist'.
2318
2319Don't change this list directly; this list is used by `ps-face-attributes',
2320`ps-map-face' and `ps-build-reference-face-lists'.")
87a16a06
RS
2321
2322
2323(defconst ps-print-face-map-alist
2324 '((bold . 1)
2325 (italic . 2)
2326 (underline . 4)
2327 (strikeout . 8)
2328 (overline . 16)
2329 (shadow . 32)
2330 (box . 64)
2331 (outline . 128))
2332 "Alist of all features and the corresponding bit mask.
2333Each symbol correspond to one bit in a bit vector.")
2334
2335\f
2336;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a18ed129 2337;; Remapping Faces
87a16a06
RS
2338
2339
2340;;;###autoload
2341(defun ps-extend-face-list (face-extension-list &optional merge-p)
2342 "Extend face in `ps-print-face-extension-alist'.
2343
a18ed129
RS
2344If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2345with face extension in `ps-print-face-extension-alist'; otherwise, overrides.
87a16a06
RS
2346
2347The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2348
2349See `ps-extend-face' for documentation."
2350 (while face-extension-list
2351 (ps-extend-face (car face-extension-list) merge-p)
2352 (setq face-extension-list (cdr face-extension-list))))
2353
2354
2355;;;###autoload
2356(defun ps-extend-face (face-extension &optional merge-p)
2357 "Extend face in `ps-print-face-extension-alist'.
2358
a18ed129
RS
2359If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged
2360with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
87a16a06
RS
2361
2362The elements of FACE-EXTENSION list have the form:
2363
2364 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2365
2366FACE-NAME is a face name symbol.
2367
2368FOREGROUND and BACKGROUND may be nil or a string that denotes the
2369foreground and background colors respectively.
2370
2371EXTENSION is one of the following symbols:
2372 bold - use bold font.
2373 italic - use italic font.
2374 underline - put a line under text.
2375 strikeout - like underline, but the line is in middle of text.
2376 overline - like underline, but the line is over the text.
2377 shadow - text will have a shadow.
2378 box - text will be surrounded by a box.
a18ed129 2379 outline - print characters as hollow outlines.
87a16a06
RS
2380
2381If EXTENSION is any other symbol, it is ignored."
2382 (let* ((face-name (nth 0 face-extension))
2383 (foreground (nth 1 face-extension))
2384 (background (nth 2 face-extension))
2385 (ps-face (cdr (assq face-name ps-print-face-extension-alist)))
2386 (face-vector (or ps-face (vector 0 nil nil)))
2387 (face-bit (ps-extension-bit face-extension)))
2388 ;; extend face
2389 (aset face-vector 0 (if merge-p
2390 (logior (aref face-vector 0) face-bit)
2391 face-bit))
2392 (and foreground (stringp foreground) (aset face-vector 1 foreground))
2393 (and background (stringp background) (aset face-vector 2 background))
2394 ;; if face does not exist, insert it
2395 (or ps-face
2396 (setq ps-print-face-extension-alist
2397 (cons (cons face-name face-vector)
2398 ps-print-face-extension-alist)))))
2399
2400
2401(defun ps-extension-bit (face-extension)
2402 (let ((face-bit 0))
2403 ;; map valid symbol extension to bit vector
2404 (setq face-extension (cdr (cdr face-extension)))
2405 (while (setq face-extension (cdr face-extension))
2406 (setq face-bit (logior face-bit
2407 (or (cdr (assq (car face-extension)
2408 ps-print-face-map-alist))
2409 0))))
2410 face-bit))
2411
2412\f
857686a6
RS
2413;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2414;; Adapted from font-lock:
2415;; Originally face attributes were specified via `font-lock-face-attributes'.
2416;; Users then changed the default face attributes by setting that variable.
2417;; However, we try and be back-compatible and respect its value if set except
2418;; for faces where M-x customize has been used to save changes for the face.
2419
2420(defun ps-font-lock-face-attributes ()
2421 (and (boundp 'font-lock-mode) (symbol-value 'font-lock-mode)
2422 (boundp 'font-lock-face-attributes)
2423 (let ((face-attributes font-lock-face-attributes))
2424 (while face-attributes
2425 (let* ((face-attribute (pop face-attributes))
2426 (face (car face-attribute)))
2427 ;; Rustle up a `defface' SPEC from a
2428 ;; `font-lock-face-attributes' entry.
2429 (unless (get face 'saved-face)
2430 (let ((foreground (nth 1 face-attribute))
2431 (background (nth 2 face-attribute))
2432 (bold-p (nth 3 face-attribute))
2433 (italic-p (nth 4 face-attribute))
2434 (underline-p (nth 5 face-attribute))
2435 face-spec)
2436 (when foreground
2437 (setq face-spec (cons ':foreground
2438 (cons foreground face-spec))))
2439 (when background
2440 (setq face-spec (cons ':background
2441 (cons background face-spec))))
2442 (when bold-p
2443 (setq face-spec (append '(:bold t) face-spec)))
2444 (when italic-p
2445 (setq face-spec (append '(:italic t) face-spec)))
2446 (when underline-p
2447 (setq face-spec (append '(:underline t) face-spec)))
2448 (custom-declare-face face (list (list t face-spec)) nil)
2449 )))))))
2450
2451\f
87a16a06
RS
2452;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2453;; Internal functions and variables
2454
2455
a18ed129 2456(defun ps-print-without-faces (from to &optional filename region-p)
857686a6 2457 (ps-spool-without-faces from to region-p)
87a16a06
RS
2458 (ps-do-despool filename))
2459
2460
a18ed129
RS
2461(defun ps-spool-without-faces (from to &optional region-p)
2462 (ps-printing-region region-p)
87a16a06
RS
2463 (ps-generate (current-buffer) from to 'ps-generate-postscript))
2464
2465
a18ed129 2466(defun ps-print-with-faces (from to &optional filename region-p)
857686a6 2467 (ps-spool-with-faces from to region-p)
87a16a06
RS
2468 (ps-do-despool filename))
2469
2470
a18ed129
RS
2471(defun ps-spool-with-faces (from to &optional region-p)
2472 (ps-printing-region region-p)
87a16a06
RS
2473 (ps-generate (current-buffer) from to 'ps-generate-postscript-with-faces))
2474
2475
a18ed129
RS
2476(defsubst ps-count-lines (from to)
2477 (+ (count-lines from to)
857686a6
RS
2478 (save-excursion
2479 (goto-char to)
2480 (if (= (current-column) 0) 1 0))))
87a16a06
RS
2481
2482
a18ed129
RS
2483(defvar ps-printing-region nil
2484 "Variable used to indicate if it is printing a region.
2485If non-nil, it is a cons, the car of which is the line number
2486where the region begins, and its cdr is the total number of lines
2487in the buffer. Formatting functions can use this information
2488to print the original line number (and not the number of lines printed),
2489and to indicate in the header that the printout is of a partial file.")
87a16a06
RS
2490
2491
a18ed129
RS
2492(defun ps-printing-region (region-p)
2493 (setq ps-printing-region
2494 (and region-p
2495 (cons (ps-count-lines (point-min) (region-beginning))
2496 (ps-count-lines (point-min) (point-max))))))
87a16a06
RS
2497
2498\f
12d89a2e
RS
2499;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2500;; Internal functions
2501
bcc0d457 2502(defun ps-line-lengths-internal ()
87a16a06 2503 "Display the correspondence between a line length and a font size,
bcc0d457
RS
2504using the current ps-print setup.
2505Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
2506 (let ((buf (get-buffer-create "*Line-lengths*"))
2507 (ifs ps-font-size) ; initial font size
2508 (icw ps-avg-char-width) ; initial character width
2509 (print-width (progn (ps-get-page-dimensions)
2510 ps-print-width))
2511 (ps-setup (ps-setup)) ; setup for the current buffer
2512 (fs-min 5) ; minimum font size
2513 cw-min ; minimum character width
2514 nb-cpl-max ; maximum nb of characters per line
2515 (fs-max 14) ; maximum font size
2516 cw-max ; maximum character width
2517 nb-cpl-min ; minimum nb of characters per line
2518 fs ; current font size
2519 cw ; current character width
2520 nb-cpl ; current nb of characters per line
2521 )
2522 (setq cw-min (/ (* icw fs-min) ifs)
2523 nb-cpl-max (floor (/ print-width cw-min))
2524 cw-max (/ (* icw fs-max) ifs)
8bd22fcf
KH
2525 nb-cpl-min (floor (/ print-width cw-max))
2526 nb-cpl nb-cpl-min)
bcc0d457
RS
2527 (set-buffer buf)
2528 (goto-char (point-max))
8bd22fcf
KH
2529 (or (bolp) (insert "\n"))
2530 (insert ps-setup
2531 "nb char per line / font size\n")
bcc0d457 2532 (while (<= nb-cpl nb-cpl-max)
8bd22fcf
KH
2533 (setq cw (/ print-width (float nb-cpl))
2534 fs (/ (* ifs cw) icw))
bcc0d457
RS
2535 (insert (format "%3s %s\n" nb-cpl fs))
2536 (setq nb-cpl (1+ nb-cpl)))
2537 (insert "\n")
2538 (display-buffer buf 'not-this-window)))
2539
2540(defun ps-nb-pages (nb-lines)
87a16a06 2541 "Display an approximate correspondence between a font size and the number
bcc0d457
RS
2542of pages the number of lines would require to print
2543using the current ps-print setup."
2544 (let ((buf (get-buffer-create "*Nb-Pages*"))
2545 (ifs ps-font-size) ; initial font size
2546 (ilh ps-line-height) ; initial line height
2547 (page-height (progn (ps-get-page-dimensions)
2548 ps-print-height))
2549 (ps-setup (ps-setup)) ; setup for the current buffer
2550 (fs-min 4) ; minimum font size
2551 lh-min ; minimum line height
2552 nb-lpp-max ; maximum nb of lines per page
2553 nb-page-min ; minimum nb of pages
2554 (fs-max 14) ; maximum font size
2555 lh-max ; maximum line height
2556 nb-lpp-min ; minimum nb of lines per page
2557 nb-page-max ; maximum nb of pages
2558 fs ; current font size
2559 lh ; current line height
2560 nb-lpp ; current nb of lines per page
2561 nb-page ; current nb of pages
2562 )
2563 (setq lh-min (/ (* ilh fs-min) ifs)
2564 nb-lpp-max (floor (/ page-height lh-min))
2565 nb-page-min (ceiling (/ (float nb-lines) nb-lpp-max))
2566 lh-max (/ (* ilh fs-max) ifs)
2567 nb-lpp-min (floor (/ page-height lh-max))
8bd22fcf
KH
2568 nb-page-max (ceiling (/ (float nb-lines) nb-lpp-min))
2569 nb-page nb-page-min)
bcc0d457
RS
2570 (set-buffer buf)
2571 (goto-char (point-max))
8bd22fcf
KH
2572 (or (bolp) (insert "\n"))
2573 (insert ps-setup
2574 (format "%d lines\n" nb-lines)
2575 "nb page / font size\n")
bcc0d457
RS
2576 (while (<= nb-page nb-page-max)
2577 (setq nb-lpp (ceiling (/ nb-lines (float nb-page)))
2578 lh (/ page-height nb-lpp)
2579 fs (/ (* ifs lh) ilh))
2580 (insert (format "%s %s\n" nb-page fs))
2581 (setq nb-page (1+ nb-page)))
2582 (insert "\n")
2583 (display-buffer buf 'not-this-window)))
2584
8bd22fcf
KH
2585(defun ps-error-scale-font ()
2586 (error "Don't have data to scale font %s.\nKnown fonts families are:\n%s"
2587 ps-font-family
2588 (mapcar 'car ps-font-info-database)))
2589
bcc0d457
RS
2590(defun ps-select-font ()
2591 "Choose the font name and size (scaling data)."
8bd22fcf
KH
2592 (let ((assoc (cdr (assq ps-font-family ps-font-info-database)))
2593 fn fb fi bi sz lh sw aw)
2594 (or assoc (ps-error-scale-font))
2595 (setq fn (nth 0 assoc)
2596 fb (nth 1 assoc)
2597 fi (nth 2 assoc)
2598 bi (nth 3 assoc)
2599 sz (nth 4 assoc)
2600 lh (nth 5 assoc)
2601 sw (nth 6 assoc)
2602 aw (nth 7 assoc)
2603
2604 ps-font fn
2605 ps-font-bold fb
2606 ps-font-italic fi
2607 ps-font-bold-italic bi
2608 ;; These data just need to be rescaled:
2609 ps-line-height (/ (* lh ps-font-size) sz)
2610 ps-space-width (/ (* sw ps-font-size) sz)
2611 ps-avg-char-width (/ (* aw ps-font-size) sz))
bcc0d457
RS
2612 ps-font-family))
2613
2614(defun ps-select-header-font ()
2615 "Choose the font name and size (scaling data) for the header."
8bd22fcf
KH
2616 (let ((assoc (cdr (assq ps-header-font-family ps-font-info-database)))
2617 fn fb fi bi sz lh sw aw)
2618 (or assoc (ps-error-scale-font))
2619 (setq fn (nth 0 assoc)
2620 fb (nth 1 assoc)
2621 fi (nth 2 assoc)
2622 bi (nth 3 assoc)
2623 sz (nth 4 assoc)
2624 lh (nth 5 assoc)
2625 sw (nth 6 assoc)
2626 aw (nth 7 assoc)
2627
2628 ;; Font name
2629 ps-header-font fn
2630 ps-header-title-font fb
2631 ;; Line height: These data just need to be rescaled:
2632 ps-header-title-line-height (/ (* lh ps-header-title-font-size) sz)
2633 ps-header-line-height (/ (* lh ps-header-font-size) sz))
bcc0d457
RS
2634 ps-header-font-family))
2635
12d89a2e 2636(defun ps-get-page-dimensions ()
bcc0d457
RS
2637 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
2638 page-width page-height)
2639 (cond
2640 ((null page-dimensions)
2641 (error "`ps-paper-type' must be one of:\n%s"
2642 (mapcar 'car ps-page-dimensions-database)))
2643 ((< ps-number-of-columns 1)
8bd22fcf
KH
2644 (error "The number of columns %d should not be negative"
2645 ps-number-of-columns)))
bcc0d457
RS
2646
2647 (ps-select-font)
2648 (ps-select-header-font)
2649
2650 (setq page-width (ps-page-dimensions-get-width page-dimensions)
2651 page-height (ps-page-dimensions-get-height page-dimensions))
2652
2653 ;; Landscape mode
2654 (if ps-landscape-mode
2655 ;; exchange width and height
2656 (setq page-width (prog1 page-height (setq page-height page-width))))
2657
2658 ;; It is used to get the lower right corner (only in landscape mode)
2659 (setq ps-landscape-page-height page-height)
2660
2661 ;; | lm | text | ic | text | ic | text | rm |
2662 ;; page-width == lm + n * pw + (n - 1) * ic + rm
2663 ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
8bd22fcf
KH
2664 (setq ps-print-width (/ (- page-width
2665 ps-left-margin ps-right-margin
2666 (* (1- ps-number-of-columns) ps-inter-column))
2667 ps-number-of-columns))
bcc0d457
RS
2668 (if (<= ps-print-width 0)
2669 (error "Bad horizontal layout:
2670page-width == %s
2671ps-left-margin == %s
2672ps-right-margin == %s
2673ps-inter-column == %s
2674ps-number-of-columns == %s
2675| lm | text | ic | text | ic | text | rm |
2676page-width == lm + n * print-width + (n - 1) * ic + rm
2677=> print-width == %d !"
2678 page-width
2679 ps-left-margin
2680 ps-right-margin
2681 ps-inter-column
2682 ps-number-of-columns
2683 ps-print-width))
2684
2685 (setq ps-print-height
2686 (- page-height ps-bottom-margin ps-top-margin))
2687 (if (<= ps-print-height 0)
2688 (error "Bad vertical layout:
2689ps-top-margin == %s
2690ps-bottom-margin == %s
2691page-height == bm + print-height + tm
2692=> print-height == %d !"
2693 ps-top-margin
2694 ps-bottom-margin
2695 ps-print-height))
2696 ;; If headers are turned on, deduct the height of the header from
2697 ;; the print height.
8bd22fcf
KH
2698 (if ps-print-header
2699 (setq ps-header-pad (* ps-header-line-pad ps-header-title-line-height)
2700 ps-print-height (- ps-print-height
2701 ps-header-offset
2702 ps-header-pad
2703 ps-header-title-line-height
2704 (* ps-header-line-height (1- ps-header-lines))
2705 ps-header-pad)))
bcc0d457
RS
2706 (if (<= ps-print-height 0)
2707 (error "Bad vertical layout:
2708ps-top-margin == %s
2709ps-bottom-margin == %s
2710ps-header-offset == %s
2711ps-header-pad == %s
2712header-height == %s
2713page-height == bm + print-height + tm - ho - hh
2714=> print-height == %d !"
2715 ps-top-margin
2716 ps-bottom-margin
2717 ps-header-offset
2718 ps-header-pad
2719 (+ ps-header-pad
2720 ps-header-title-line-height
8bd22fcf 2721 (* ps-header-line-height (1- ps-header-lines))
bcc0d457
RS
2722 ps-header-pad)
2723 ps-print-height))))
ef2cbb24 2724
12d89a2e 2725(defun ps-print-preprint (&optional filename)
8bd22fcf
KH
2726 (and filename
2727 (or (numberp filename)
2728 (listp filename))
2729 (let* ((name (concat (buffer-name) ".ps"))
2730 (prompt (format "Save PostScript to file: (default %s) " name))
2731 (res (read-file-name prompt default-directory name nil)))
2732 (if (file-directory-p res)
2733 (expand-file-name name (file-name-as-directory res))
2734 res))))
12d89a2e
RS
2735
2736;; The following functions implement a simple list-buffering scheme so
2737;; that ps-print doesn't have to repeatedly switch between buffers
857686a6
RS
2738;; while spooling. The functions `ps-output' and `ps-output-string' build
2739;; up the lists; the function `ps-flush-output' takes the lists and
12d89a2e
RS
2740;; insert its contents into the spool buffer (*PostScript*).
2741
857686a6
RS
2742(defvar ps-string-escape-codes
2743 (let ((table (make-vector 256 nil))
2744 (char ?\000))
2745 ;; control characters
2746 (while (<= char ?\037)
2747 (aset table char (format "\\%03o" char))
2748 (setq char (1+ char)))
2749 ;; printable characters
2750 (while (< char ?\177)
2751 (aset table char (format "%c" char))
2752 (setq char (1+ char)))
2753 ;; DEL and 8-bit characters
2754 (while (<= char ?\377)
2755 (aset table char (format "\\%o" char))
2756 (setq char (1+ char)))
2757 ;; Override ASCII formatting characters with named escape code:
2758 (aset table ?\n "\\n") ; [NL] linefeed
2759 (aset table ?\r "\\r") ; [CR] carriage return
2760 (aset table ?\t "\\t") ; [HT] horizontal tab
2761 (aset table ?\b "\\b") ; [BS] backspace
2762 (aset table ?\f "\\f") ; [NP] form feed
2763 ;; Escape PostScript escape and string delimiter characters:
2764 (aset table ?\\ "\\\\")
2765 (aset table ?\( "\\(")
2766 (aset table ?\) "\\)")
2767 table)
2768 "Vector used to map characters to PostScript string escape codes.")
2769
12d89a2e
RS
2770(defun ps-output-string-prim (string)
2771 (insert "(") ;insert start-string delimiter
2772 (save-excursion ;insert string
2773 (insert string))
12d89a2e 2774 ;; Find and quote special characters as necessary for PS
857686a6
RS
2775 (while (re-search-forward "[\000-\037\177-\377()\\]" nil t)
2776 (let ((special (preceding-char)))
2777 (delete-char -1)
2778 (insert (aref ps-string-escape-codes special))))
12d89a2e
RS
2779 (goto-char (point-max))
2780 (insert ")")) ;insert end-string delimiter
ef2cbb24 2781
12d89a2e 2782(defun ps-init-output-queue ()
8bd22fcf
KH
2783 (setq ps-output-head '("")
2784 ps-output-tail ps-output-head))
ef2cbb24 2785
12d89a2e
RS
2786(defun ps-output (&rest args)
2787 (setcdr ps-output-tail args)
2788 (while (cdr ps-output-tail)
2789 (setq ps-output-tail (cdr ps-output-tail))))
ef2cbb24 2790
12d89a2e
RS
2791(defun ps-output-string (string)
2792 (ps-output t string))
ef2cbb24 2793
87a16a06
RS
2794(defun ps-output-list (the-list)
2795 (mapcar 'ps-output the-list))
2796
12d89a2e
RS
2797(defun ps-flush-output ()
2798 (save-excursion
2799 (set-buffer ps-spool-buffer)
2800 (goto-char (point-max))
2801 (while ps-output-head
2802 (let ((it (car ps-output-head)))
2803 (if (not (eq t it))
2804 (insert it)
2805 (setq ps-output-head (cdr ps-output-head))
2806 (ps-output-string-prim (car ps-output-head))))
2807 (setq ps-output-head (cdr ps-output-head))))
2808 (ps-init-output-queue))
2809
2810(defun ps-insert-file (fname)
2811 (ps-flush-output)
12d89a2e 2812 ;; Check to see that the file exists and is readable; if not, throw
87a16a06
RS
2813 ;; an error.
2814 (or (file-readable-p fname)
12d89a2e 2815 (error "Could not read file `%s'" fname))
12d89a2e
RS
2816 (save-excursion
2817 (set-buffer ps-spool-buffer)
2818 (goto-char (point-max))
2819 (insert-file fname)))
06fb6aab 2820
12d89a2e
RS
2821;; These functions insert the arrays that define the contents of the
2822;; headers.
ef2cbb24 2823
12d89a2e
RS
2824(defun ps-generate-header-line (fonttag &optional content)
2825 (ps-output " [ " fonttag " ")
2826 (cond
2827 ;; Literal strings should be output as is -- the string must
2828 ;; contain its own PS string delimiters, '(' and ')', if necessary.
2829 ((stringp content)
2830 (ps-output content))
2831
2832 ;; Functions are called -- they should return strings; they will be
2833 ;; inserted as strings and the PS string delimiters added.
2834 ((and (symbolp content) (fboundp content))
2835 (ps-output-string (funcall content)))
2836
2837 ;; Variables will have their contents inserted. They should
2838 ;; contain strings, and will be inserted as strings.
2839 ((and (symbolp content) (boundp content))
2840 (ps-output-string (symbol-value content)))
2841
2842 ;; Anything else will get turned into an empty string.
2843 (t
2844 (ps-output-string "")))
2845 (ps-output " ]\n"))
2846
2847(defun ps-generate-header (name contents)
2848 (ps-output "/" name " [\n")
2849 (if (> ps-header-lines 0)
2850 (let ((count 1))
2851 (ps-generate-header-line "/h0" (car contents))
2852 (while (and (< count ps-header-lines)
2853 (setq contents (cdr contents)))
2854 (ps-generate-header-line "/h1" (car contents))
8bd22fcf 2855 (setq count (1+ count)))
12d89a2e
RS
2856 (ps-output "] def\n"))))
2857
2858(defun ps-output-boolean (name bool)
2859 (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
ef2cbb24 2860
06fb6aab 2861
87a16a06
RS
2862(defun ps-background-pages (page-list func)
2863 (if page-list
2864 (mapcar
2865 '(lambda (pages)
2866 (let ((start (if (consp pages) (car pages) pages))
2867 (end (if (consp pages) (cdr pages) pages)))
2868 (and (integerp start) (integerp end) (<= start end)
2869 (add-to-list 'ps-background-pages (vector start end func)))))
2870 page-list)
2871 (setq ps-background-all-pages (cons func ps-background-all-pages))))
2872
2873
2874(defun ps-get-boundingbox ()
2875 (save-excursion
2876 (set-buffer ps-spool-buffer)
2877 (save-excursion
2878 (if (re-search-forward
2879 "^%%BoundingBox:\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)"
2880 nil t)
2881 (vector (string-to-number ; lower x
2882 (buffer-substring (match-beginning 1) (match-end 1)))
2883 (string-to-number ; lower y
2884 (buffer-substring (match-beginning 2) (match-end 2)))
2885 (string-to-number ; upper x
2886 (buffer-substring (match-beginning 3) (match-end 3)))
2887 (string-to-number ; upper y
2888 (buffer-substring (match-beginning 4) (match-end 4))))
2889 (vector 0 0 0 0)))))
2890
2891
2892;; Emacs understands the %f format; we'll use it to limit color RGB values
2893;; to three decimals to cut down some on the size of the PostScript output.
2894;; Lucid emacsen will have to make do with %s (princ) for floats.
2895
2896(defvar ps-float-format (if (eq ps-print-emacs-type 'emacs)
2897 "%0.3f " ; emacs
2898 "%s ")) ; Lucid emacsen
2899
2900
2901(defun ps-float-format (value &optional default)
2902 (let ((literal (or value default)))
2903 (if literal
2904 (format (if (numberp literal)
2905 ps-float-format
2906 "%s ")
2907 literal)
2908 " ")))
2909
2910
2911(defun ps-background-text ()
2912 (mapcar
2913 '(lambda (text)
2914 (setq ps-background-text-count (1+ ps-background-text-count))
2915 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count))
2916 (ps-output-string (nth 0 text)) ; text
2917 (ps-output
2918 "\n"
2919 (ps-float-format (nth 4 text) 200.0) ; font size
2920 (format "/%s " (or (nth 3 text) "Times-Roman")) ; font name
2921 (ps-float-format (nth 6 text)
2922 "PrintHeight PrintPageWidth atan") ; rotation
2923 (ps-float-format (nth 5 text) 0.85) ; gray
2924 (ps-float-format (nth 1 text) "0") ; x position
2925 (ps-float-format (nth 2 text) "BottomMargin") ; y position
2926 "\nShowBackText} def\n")
2927 (ps-background-pages (nthcdr 7 text) ; page list
2928 (format "ShowBackText-%d\n"
2929 ps-background-text-count)))
2930 ps-print-background-text))
2931
2932
2933(defun ps-background-image ()
2934 (mapcar
2935 '(lambda (image)
2936 (let ((image-file (expand-file-name (nth 0 image))))
2937 (if (file-readable-p image-file)
2938 (progn
2939 (setq ps-background-image-count (1+ ps-background-image-count))
2940 (ps-output
2941 (format "/ShowBackImage-%d {\n--back-- " ps-background-image-count)
2942 (ps-float-format (nth 5 image) 0.0) ; rotation
2943 (ps-float-format (nth 3 image) 1.0) ; x scale
2944 (ps-float-format (nth 4 image) 1.0) ; y scale
2945 (ps-float-format (nth 1 image) ; x position
2946 "PrintPageWidth 2 div")
2947 (ps-float-format (nth 2 image) ; y position
2948 "PrintHeight 2 div BottomMargin add")
2949 "\nBeginBackImage\n")
2950 (ps-insert-file image-file)
2951 ;; coordinate adjustment to centralize image
2952 ;; around x and y position
2953 (let ((box (ps-get-boundingbox)))
2954 (save-excursion
2955 (set-buffer ps-spool-buffer)
2956 (save-excursion
2957 (if (re-search-backward "^--back--" nil t)
2958 (replace-match
2959 (format "%s %s"
2960 (ps-float-format
2961 (- (+ (/ (- (aref box 2) (aref box 0)) 2.0)
2962 (aref box 0))))
2963 (ps-float-format
2964 (- (+ (/ (- (aref box 3) (aref box 1)) 2.0)
2965 (aref box 1)))))
2966 t)))))
2967 (ps-output "\nEndBackImage} def\n")
2968 (ps-background-pages (nthcdr 6 image) ; page list
2969 (format "ShowBackImage-%d\n"
2970 ps-background-image-count))))))
2971 ps-print-background-image))
2972
2973
a18ed129 2974(defun ps-background (page-number)
87a16a06
RS
2975 (let (has-local-background)
2976 (mapcar '(lambda (range)
a18ed129
RS
2977 (and (<= (aref range 0) page-number)
2978 (<= page-number (aref range 1))
87a16a06
RS
2979 (if has-local-background
2980 (ps-output (aref range 2))
2981 (setq has-local-background t)
2982 (ps-output "/printLocalBackground {\n"
2983 (aref range 2)))))
2984 ps-background-pages)
2985 (and has-local-background (ps-output "} def\n"))))
2986
2987
ef2cbb24 2988(defun ps-begin-file ()
bcc0d457 2989 (ps-get-page-dimensions)
a18ed129 2990 (setq ps-showline-count (if ps-printing-region (car ps-printing-region) 1)
87a16a06
RS
2991 ps-background-text-count 0
2992 ps-background-image-count 0
2993 ps-background-pages nil
2994 ps-background-all-pages nil)
12d89a2e 2995
8bd22fcf
KH
2996 (ps-output ps-adobe-tag
2997 "%%Title: " (buffer-name) ; Take job name from name of
2998 ; first buffer printed
2999 "\n%%Creator: " (user-full-name)
857686a6
RS
3000 " (using ps-print v" ps-print-version
3001 ")\n%%CreationDate: "
87a16a06
RS
3002 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy)
3003 "\n%%Orientation: "
8bd22fcf
KH
3004 (if ps-landscape-mode "Landscape" "Portrait")
3005 "\n%% DocumentFonts: Times-Roman Times-Italic "
12d89a2e 3006 ps-font " " ps-font-bold " " ps-font-italic " "
bcc0d457 3007 ps-font-bold-italic " "
8bd22fcf
KH
3008 ps-header-font " " ps-header-title-font
3009 "\n%%Pages: (atend)\n"
3010 "%%EndComments\n\n")
12d89a2e 3011
bcc0d457 3012 (ps-output-boolean "LandscapeMode" ps-landscape-mode)
8bd22fcf 3013 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns)
12d89a2e 3014
8bd22fcf
KH
3015 (format "/LandscapePageHeight %s def\n" ps-landscape-page-height)
3016 (format "/PrintPageWidth %s def\n"
87a16a06
RS
3017 (- (* (+ ps-print-width ps-inter-column)
3018 ps-number-of-columns)
8bd22fcf
KH
3019 ps-inter-column))
3020 (format "/PrintWidth %s def\n" ps-print-width)
3021 (format "/PrintHeight %s def\n" ps-print-height)
12d89a2e 3022
8bd22fcf
KH
3023 (format "/LeftMargin %s def\n" ps-left-margin)
3024 (format "/RightMargin %s def\n" ps-right-margin) ; not used
3025 (format "/InterColumn %s def\n" ps-inter-column)
bcc0d457 3026
8bd22fcf
KH
3027 (format "/BottomMargin %s def\n" ps-bottom-margin)
3028 (format "/TopMargin %s def\n" ps-top-margin) ; not used
3029 (format "/HeaderOffset %s def\n" ps-header-offset)
3030 (format "/HeaderPad %s def\n" ps-header-pad))
06fb6aab 3031
bcc0d457
RS
3032 (ps-output-boolean "PrintHeader" ps-print-header)
3033 (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame)
3034 (ps-output-boolean "ShowNofN" ps-show-n-of-n)
3035 (ps-output-boolean "Duplex" ps-spool-duplex)
3036
87a16a06
RS
3037 (ps-output (format "/LineHeight %s def\n" ps-line-height)
3038 (format "/LinesPerColumn %d def\n"
a18ed129 3039 (round (/ (+ ps-print-height
87a16a06
RS
3040 (* ps-line-height 0.45))
3041 ps-line-height))))
3042
535efc38 3043 (ps-output-boolean "Zebra" ps-zebra-stripes)
87a16a06 3044 (ps-output-boolean "PrintLineNumber" ps-line-number)
857686a6 3045 (ps-output (format "/ZebraHeight %d def\n" ps-zebra-stripe-height)
8bd22fcf 3046 (format "/Lines %d def\n"
a18ed129
RS
3047 (if ps-printing-region
3048 (cdr ps-printing-region)
8bd22fcf
KH
3049 (ps-count-lines (point-min) (point-max))))
3050 "/PageCount 0 def\n") ; set total page number
3051 ; when printing has finished
3052 ; (see `ps-generate')
87a16a06
RS
3053
3054 (ps-background-text)
3055 (ps-background-image)
3056 (setq ps-background-all-pages (nreverse ps-background-all-pages)
3057 ps-background-pages (nreverse ps-background-pages))
12d89a2e 3058
bcc0d457 3059 (ps-output ps-print-prologue-1)
12d89a2e 3060
87a16a06
RS
3061 (ps-output "/printGlobalBackground {\n")
3062 (ps-output-list ps-background-all-pages)
3063 (ps-output "} def\n/printLocalBackground {\n} def\n")
3064
bcc0d457 3065 ;; Header fonts
8bd22fcf
KH
3066 (ps-output (format "/h0 %s /%s DefFont\n" ; /h0 14 /Helvetica-Bold DefFont
3067 ps-header-title-font-size ps-header-title-font)
3068 (format "/h1 %s /%s DefFont\n" ; /h1 12 /Helvetica DefFont
3069 ps-header-font-size ps-header-font))
bcc0d457
RS
3070
3071 (ps-output ps-print-prologue-2)
3072
3073 ;; Text fonts
8bd22fcf
KH
3074 (ps-output (format "/f0 %s /%s DefFont\n" ps-font-size ps-font)
3075 (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold)
3076 (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic)
3077 (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic))
bcc0d457 3078
8bd22fcf
KH
3079 (ps-output "\nBeginDoc\n\n"
3080 "%%EndPrologue\n"))
ef2cbb24 3081
12d89a2e
RS
3082(defun ps-header-dirpart ()
3083 (let ((fname (buffer-file-name)))
3084 (if fname
3085 (if (string-equal (buffer-name) (file-name-nondirectory fname))
3086 (file-name-directory fname)
3087 fname)
3088 "")))
ef2cbb24 3089
12d89a2e 3090(defun ps-get-buffer-name ()
bcc0d457
RS
3091 (cond
3092 ;; Indulge Jim this little easter egg:
3093 ((string= (buffer-name) "ps-print.el")
3094 "Hey, Cool! It's ps-print.el!!!")
3095 ;; Indulge Jack this other little easter egg:
3096 ((string= (buffer-name) "sokoban.el")
3097 "Super! C'est sokoban.el!")
87a16a06 3098 (t (concat
a18ed129 3099 (and ps-printing-region "Subset of: ")
87a16a06
RS
3100 (buffer-name)
3101 (and (buffer-modified-p) " (unsaved)")))))
ef2cbb24 3102
12d89a2e 3103(defun ps-begin-job ()
857686a6
RS
3104 (setq ps-page-count 0
3105 ps-control-or-escape-regexp
3106 (cond ((eq ps-print-control-characters '8-bit) "[\000-\037\177-\377]")
3107 ((eq ps-print-control-characters 'control-8-bit) "[\000-\037\177-\237]")
3108 ((eq ps-print-control-characters 'control) "[\000-\037\177]")
3109 (t "[\t\n\f]"))))
ef2cbb24
RS
3110
3111(defun ps-end-file ()
8bd22fcf
KH
3112 (ps-output "\nEndDoc\n\n%%Trailer\n%%Pages: "
3113 (format "%d" (1+ (/ (1- ps-page-count) ps-number-of-columns)))
3114 "\n%%EOF\n"))
87a16a06
RS
3115
3116
ef2cbb24
RS
3117(defun ps-next-page ()
3118 (ps-end-page)
12d89a2e
RS
3119 (ps-flush-output)
3120 (ps-begin-page))
3121
a18ed129
RS
3122(defun ps-header-page (&optional inc-p)
3123 (if (zerop (mod ps-page-count ps-number-of-columns))
3124 ;; Print only when a new real page begins.
3125 (let ((page-number (1+ (/ ps-page-count ps-number-of-columns))))
3126 (ps-output (format "\n%%%%Page: %d %d\n" page-number page-number))
3127 (ps-output "BeginDSCPage\n")
3128 (ps-background page-number)
3129 (and inc-p (incf ps-page-count)))
3130 ;; Print when any other page begins.
3131 (ps-output "BeginDSCPage\n")))
3132
8bd22fcf 3133(defun ps-begin-page ()
12d89a2e 3134 (ps-get-page-dimensions)
8bd22fcf
KH
3135 (setq ps-width-remaining ps-print-width
3136 ps-height-remaining ps-print-height)
12d89a2e 3137
a18ed129 3138 (ps-header-page)
12d89a2e 3139
87a16a06
RS
3140 (ps-output (format "/LineNumber %d def\n" ps-showline-count)
3141 (format "/PageNumber %d def\n" (incf ps-page-count)))
12d89a2e 3142
090be653
RS
3143 (when ps-print-header
3144 (ps-generate-header "HeaderLinesLeft" ps-left-header)
3145 (ps-generate-header "HeaderLinesRight" ps-right-header)
3146 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
12d89a2e
RS
3147
3148 (ps-output "BeginPage\n")
87a16a06
RS
3149 (ps-set-font ps-current-font)
3150 (ps-set-bg ps-current-bg)
3151 (ps-set-color ps-current-color))
ef2cbb24
RS
3152
3153(defun ps-end-page ()
a18ed129 3154 (ps-output "EndPage\nEndDSCPage\n"))
12d89a2e
RS
3155
3156(defun ps-dummy-page ()
a18ed129
RS
3157 (ps-header-page t)
3158 (ps-output "/PrintHeader false def
12d89a2e
RS
3159BeginPage
3160EndPage
3161EndDSCPage\n"))
06fb6aab 3162
ef2cbb24 3163(defun ps-next-line ()
87a16a06 3164 (setq ps-showline-count (1+ ps-showline-count))
12d89a2e 3165 (if (< ps-height-remaining ps-line-height)
ef2cbb24 3166 (ps-next-page)
8bd22fcf
KH
3167 (setq ps-width-remaining ps-print-width
3168 ps-height-remaining (- ps-height-remaining ps-line-height))
3169 (ps-output "HL\n")))
ef2cbb24
RS
3170
3171(defun ps-continue-line ()
12d89a2e
RS
3172 (if (< ps-height-remaining ps-line-height)
3173 (ps-next-page)
8bd22fcf
KH
3174 (setq ps-width-remaining ps-print-width
3175 ps-height-remaining (- ps-height-remaining ps-line-height))
3176 (ps-output "SL\n")))
12d89a2e
RS
3177
3178(defun ps-find-wrappoint (from to char-width)
3179 (let ((avail (truncate (/ ps-width-remaining char-width)))
3180 (todo (- to from)))
3181 (if (< todo avail)
3182 (cons to (* todo char-width))
3183 (cons (+ from avail) ps-width-remaining))))
3184
3185(defun ps-basic-plot-string (from to &optional bg-color)
3186 (let* ((wrappoint (ps-find-wrappoint from to ps-avg-char-width))
3187 (to (car wrappoint))
055e7bf2 3188 (string (buffer-substring-no-properties from to)))
12d89a2e 3189 (ps-output-string string)
bcc0d457 3190 (ps-output " S\n")
12d89a2e
RS
3191 wrappoint))
3192
3193(defun ps-basic-plot-whitespace (from to &optional bg-color)
3194 (let* ((wrappoint (ps-find-wrappoint from to ps-space-width))
3195 (to (car wrappoint)))
12d89a2e
RS
3196 (ps-output (format "%d W\n" (- to from)))
3197 wrappoint))
3198
3199(defun ps-plot (plotfunc from to &optional bg-color)
ef2cbb24 3200 (while (< from to)
12d89a2e
RS
3201 (let* ((wrappoint (funcall plotfunc from to bg-color))
3202 (plotted-to (car wrappoint))
3203 (plotted-width (cdr wrappoint)))
8bd22fcf
KH
3204 (setq from plotted-to
3205 ps-width-remaining (- ps-width-remaining plotted-width))
12d89a2e
RS
3206 (if (< from to)
3207 (ps-continue-line))))
ef2cbb24
RS
3208 (if ps-razzle-dazzle
3209 (let* ((q-todo (- (point-max) (point-min)))
12d89a2e 3210 (q-done (- (point) (point-min)))
ef2cbb24 3211 (chunkfrac (/ q-todo 8))
857686a6 3212 (chunksize (min chunkfrac 1000)))
ef2cbb24 3213 (if (> (- q-done ps-razchunk) chunksize)
8bd22fcf 3214 (progn
ef2cbb24 3215 (setq ps-razchunk q-done)
8bd22fcf
KH
3216 (message "Formatting...%3d%%"
3217 (if (< q-todo 100)
3218 (/ (* 100 q-done) q-todo)
3219 (/ q-done (/ q-todo 100)))
3220 ))))))
12d89a2e
RS
3221
3222(defun ps-set-font (font)
8bd22fcf 3223 (ps-output (format "/f%d F\n" (setq ps-current-font font))))
12d89a2e 3224
12d89a2e
RS
3225(defun ps-set-bg (color)
3226 (if (setq ps-current-bg color)
8bd22fcf
KH
3227 (ps-output (format ps-color-format
3228 (nth 0 color) (nth 1 color) (nth 2 color))
12d89a2e
RS
3229 " true BG\n")
3230 (ps-output "false BG\n")))
3231
3232(defun ps-set-color (color)
a18ed129 3233 (setq ps-current-color (or color ps-default-fg))
8bd22fcf
KH
3234 (ps-output (format ps-color-format
3235 (nth 0 ps-current-color)
043620f4
KH
3236 (nth 1 ps-current-color) (nth 2 ps-current-color))
3237 " FG\n"))
12d89a2e 3238
12d89a2e 3239
87a16a06 3240(defvar ps-current-effect 0)
12d89a2e 3241
87a16a06
RS
3242
3243(defun ps-plot-region (from to font &optional fg-color bg-color effects)
12d89a2e
RS
3244 (if (not (equal font ps-current-font))
3245 (ps-set-font font))
06fb6aab 3246
12d89a2e
RS
3247 ;; Specify a foreground color only if one's specified and it's
3248 ;; different than the current.
3249 (if (not (equal fg-color ps-current-color))
3250 (ps-set-color fg-color))
06fb6aab 3251
12d89a2e
RS
3252 (if (not (equal bg-color ps-current-bg))
3253 (ps-set-bg bg-color))
06fb6aab 3254
87a16a06
RS
3255 ;; Specify effects (underline, overline, box, etc)
3256 (cond
3257 ((not (integerp effects))
3258 (ps-output "0 EF\n")
3259 (setq ps-current-effect 0))
3260 ((/= effects ps-current-effect)
3261 (ps-output (number-to-string effects) " EF\n")
3262 (setq ps-current-effect effects)))
ef2cbb24 3263
12d89a2e 3264 ;; Starting at the beginning of the specified region...
ef2cbb24
RS
3265 (save-excursion
3266 (goto-char from)
12d89a2e
RS
3267
3268 ;; ...break the region up into chunks separated by tabs, linefeeds,
87a16a06 3269 ;; pagefeeds, control characters, and plot each chunk.
ef2cbb24 3270 (while (< from to)
857686a6 3271 (if (re-search-forward ps-control-or-escape-regexp to t)
a18ed129 3272 ;; region with some control characters
87a16a06 3273 (let ((match (char-after (match-beginning 0))))
857686a6
RS
3274 (ps-plot 'ps-basic-plot-string from (1- (point)) bg-color)
3275 (cond
3276 ((= match ?\t) ; tab
3277 (let ((linestart (save-excursion (beginning-of-line) (point))))
3278 (forward-char -1)
3279 (setq from (+ linestart (current-column)))
3280 (if (re-search-forward "[ \t]+" to t)
3281 (ps-plot 'ps-basic-plot-whitespace
3282 from (+ linestart (current-column))
3283 bg-color))))
3284
3285 ((= match ?\n) ; newline
3286 (ps-next-line))
3287
3288 ((= match ?\f) ; form feed
3289 (ps-next-page))
3290 ; characters from ^@ to ^_ and
3291 (t ; characters from 127 to 255
3292 (ps-control-character match)))
87a16a06
RS
3293 (setq from (point)))
3294 ;; region without control characters
3295 (ps-plot 'ps-basic-plot-string from to bg-color)
3296 (setq from to)))))
3297
857686a6
RS
3298(defvar ps-string-control-codes
3299 (let ((table (make-vector 256 nil))
3300 (char ?\000))
3301 ;; control character
3302 (while (<= char ?\037)
3303 (aset table char (format "^%c" (+ char ?@)))
3304 (setq char (1+ char)))
3305 ;; printable character
3306 (while (< char ?\177)
3307 (aset table char (format "%c" char))
3308 (setq char (1+ char)))
3309 ;; DEL
3310 (aset table char "^?")
3311 ;; 8-bit character
3312 (while (<= (setq char (1+ char)) ?\377)
3313 (aset table char (format "\\%o" char)))
3314 table)
3315 "Vector used to map characters to a printable string.")
3316
3317(defun ps-control-character (char)
3318 (let* ((str (aref ps-string-control-codes char))
3319 (from (1- (point)))
87a16a06
RS
3320 (len (length str))
3321 (to (+ from len))
3322 (wrappoint (ps-find-wrappoint from to ps-avg-char-width)))
3323 (if (< (car wrappoint) to)
3324 (ps-continue-line))
3325 (setq ps-width-remaining (- ps-width-remaining (* len ps-avg-char-width)))
3326 (ps-output-string str)
3327 (ps-output " S\n")))
ef2cbb24 3328
12d89a2e
RS
3329(defun ps-color-value (x-color-value)
3330 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
3331 (/ x-color-value ps-print-color-scale))
ef2cbb24 3332
043620f4
KH
3333(defun ps-color-values (x-color)
3334 (cond ((fboundp 'x-color-values)
3335 (x-color-values x-color))
857686a6
RS
3336 ((fboundp 'color-instance-rgb-components)
3337 (if (ps-color-device)
3338 (color-instance-rgb-components
3339 (if (color-instance-p x-color)
3340 x-color
3341 (make-color-instance
3342 (if (color-specifier-p x-color)
3343 (color-name x-color)
3344 x-color))))
3345 (error "No available function to determine X color values.")))
043620f4
KH
3346 (t (error "No available function to determine X color values."))))
3347
87a16a06 3348
a18ed129
RS
3349(defun ps-face-attributes (face)
3350 "Return face attribute vector.
87a16a06 3351
a18ed129
RS
3352If FACE is not in `ps-print-face-extension-alist' or in
3353`ps-print-face-alist', insert it on `ps-print-face-alist' and
3354return the attribute vector.
87a16a06
RS
3355
3356If FACE is not a valid face name, it is used default face."
a18ed129
RS
3357 (cdr (or (assq face ps-print-face-extension-alist)
3358 (assq face ps-print-face-alist)
3359 (let* ((the-face (if (facep face) face 'default))
3360 (new-face (ps-screen-to-bit-face the-face)))
3361 (or (and (eq the-face 'default)
3362 (assq the-face ps-print-face-alist))
3363 (setq ps-print-face-alist (cons new-face ps-print-face-alist)))
3364 new-face))))
87a16a06 3365
043620f4
KH
3366
3367(defun ps-face-attribute-list (face-or-list)
3368 (if (listp face-or-list)
87a16a06 3369 ;; list of faces
857686a6
RS
3370 (let ((effects 0)
3371 foreground background face-attr)
043620f4 3372 (while face-or-list
857686a6 3373 (setq face-attr (ps-face-attributes (car face-or-list))
87a16a06
RS
3374 effects (logior effects (aref face-attr 0)))
3375 (or foreground (setq foreground (aref face-attr 1)))
3376 (or background (setq background (aref face-attr 2)))
043620f4 3377 (setq face-or-list (cdr face-or-list)))
87a16a06
RS
3378 (vector effects foreground background))
3379 ;; simple face
043620f4
KH
3380 (ps-face-attributes face-or-list)))
3381
87a16a06 3382
12d89a2e
RS
3383(defun ps-plot-with-face (from to face)
3384 (if face
87a16a06
RS
3385 (let* ((face-bit (ps-face-attribute-list face))
3386 (effect (aref face-bit 0))
3387 (foreground (aref face-bit 1))
3388 (background (aref face-bit 2))
857686a6 3389 (fg-color (if (and ps-print-color-p foreground (ps-color-device))
12d89a2e 3390 (mapcar 'ps-color-value
043620f4 3391 (ps-color-values foreground))
12d89a2e 3392 ps-default-color))
857686a6 3393 (bg-color (and ps-print-color-p background (ps-color-device)
8bd22fcf
KH
3394 (mapcar 'ps-color-value
3395 (ps-color-values background)))))
87a16a06
RS
3396 (ps-plot-region from to (logand effect 3)
3397 fg-color bg-color (lsh effect -2)))
3398 (ps-plot-region from to 0))
3399 (goto-char to))
12d89a2e
RS
3400
3401
12d89a2e 3402(defun ps-xemacs-face-kind-p (face kind kind-regex kind-list)
857686a6
RS
3403 (let* ((frame-font (or (face-font-instance face)
3404 (face-font-instance 'default)))
3405 (kind-cons (and frame-font
3406 (assq kind (font-instance-properties frame-font))))
12d89a2e
RS
3407 (kind-spec (cdr-safe kind-cons))
3408 (case-fold-search t))
12d89a2e
RS
3409 (or (and kind-spec (string-match kind-regex kind-spec))
3410 ;; Kludge-compatible:
3411 (memq face kind-list))))
3412
3413(defun ps-face-bold-p (face)
6770a60f 3414 (if (eq ps-print-emacs-type 'emacs)
06fb6aab
RS
3415 (or (face-bold-p face)
3416 (memq face ps-bold-faces))
8bd22fcf 3417 (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold" ps-bold-faces)))
12d89a2e
RS
3418
3419(defun ps-face-italic-p (face)
6770a60f 3420 (if (eq ps-print-emacs-type 'emacs)
06fb6aab
RS
3421 (or (face-italic-p face)
3422 (memq face ps-italic-faces))
8bd22fcf
KH
3423 (or (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces)
3424 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces))))
12d89a2e
RS
3425
3426(defun ps-face-underlined-p (face)
3427 (or (face-underline-p face)
3428 (memq face ps-underlined-faces)))
3429
a18ed129 3430
043620f4
KH
3431;; Ensure that face-list is fbound.
3432(or (fboundp 'face-list) (defalias 'face-list 'list-faces))
12d89a2e 3433
a18ed129 3434
12d89a2e 3435(defun ps-build-reference-face-lists ()
857686a6
RS
3436 ;; Ensure that face database is updated with faces on
3437 ;; `font-lock-face-attributes' (obsolete stuff)
3438 (ps-font-lock-face-attributes)
3439 ;; Now, rebuild reference face lists
a18ed129 3440 (setq ps-print-face-alist nil)
12d89a2e 3441 (if ps-auto-font-detect
a18ed129
RS
3442 (mapcar 'ps-map-face (face-list))
3443 (mapcar 'ps-set-face-bold ps-bold-faces)
3444 (mapcar 'ps-set-face-italic ps-italic-faces)
3445 (mapcar 'ps-set-face-underline ps-underlined-faces))
12d89a2e 3446 (setq ps-build-face-reference nil))
ef2cbb24 3447
a18ed129
RS
3448
3449(defun ps-set-face-bold (face)
3450 (ps-set-face-attribute face 1))
3451
3452(defun ps-set-face-italic (face)
3453 (ps-set-face-attribute face 2))
3454
3455(defun ps-set-face-underline (face)
3456 (ps-set-face-attribute face 4))
3457
3458
3459(defun ps-set-face-attribute (face effect)
3460 (let ((face-bit (cdr (ps-map-face face))))
3461 (aset face-bit 0 (logior (aref face-bit 0) effect))))
3462
3463
3464(defun ps-map-face (face)
3465 (let* ((face-map (ps-screen-to-bit-face face))
3466 (ps-face-bit (cdr (assq (car face-map) ps-print-face-alist))))
3467 (if ps-face-bit
3468 ;; if face exists, merge both
3469 (let ((face-bit (cdr face-map)))
3470 (aset ps-face-bit 0 (logior (aref ps-face-bit 0) (aref face-bit 0)))
3471 (or (aref ps-face-bit 1) (aset ps-face-bit 1 (aref face-bit 1)))
3472 (or (aref ps-face-bit 2) (aset ps-face-bit 2 (aref face-bit 2))))
3473 ;; if face does not exist, insert it
3474 (setq ps-print-face-alist (cons face-map ps-print-face-alist)))
3475 face-map))
3476
3477
3478(defun ps-screen-to-bit-face (face)
3479 (cons face
3480 (vector (logior (if (ps-face-bold-p face) 1 0) ; bold
3481 (if (ps-face-italic-p face) 2 0) ; italic
3482 (if (ps-face-underlined-p face) 4 0)) ; underline
3483 (face-foreground face)
3484 (face-background face))))
3485
3486
ef2cbb24
RS
3487(defun ps-mapper (extent list)
3488 (nconc list (list (list (extent-start-position extent) 'push extent)
06fb6aab 3489 (list (extent-end-position extent) 'pull extent)))
ef2cbb24
RS
3490 nil)
3491
00aa16af
RS
3492(defun ps-extent-sorter (a b)
3493 (< (extent-priority a) (extent-priority b)))
043620f4
KH
3494
3495(defun ps-print-ensure-fontified (start end)
857686a6 3496 (and (boundp 'lazy-lock-mode) (symbol-value 'lazy-lock-mode)
8bd22fcf
KH
3497 (if (fboundp 'lazy-lock-fontify-region)
3498 (lazy-lock-fontify-region start end) ; the new
3499 (lazy-lock-fontify-buffer)))) ; the old
043620f4 3500
ef2cbb24 3501(defun ps-generate-postscript-with-faces (from to)
87a16a06 3502 ;; Some initialization...
857686a6 3503 (setq ps-current-effect 0)
87a16a06 3504
00aa16af 3505 ;; Build the reference lists of faces if necessary.
12d89a2e
RS
3506 (if (or ps-always-build-face-reference
3507 ps-build-face-reference)
3508 (progn
3509 (message "Collecting face information...")
3510 (ps-build-reference-face-lists)))
00aa16af
RS
3511 ;; Set the color scale. We do it here instead of in the defvar so
3512 ;; that ps-print can be dumped into emacs. This expression can't be
3513 ;; evaluated at dump-time because X isn't initialized.
3514 (setq ps-print-color-scale
857686a6 3515 (if (and ps-print-color-p (ps-color-device))
043620f4 3516 (float (car (ps-color-values "white")))
00aa16af
RS
3517 1.0))
3518 ;; Generate some PostScript.
ef2cbb24
RS
3519 (save-restriction
3520 (narrow-to-region from to)
12d89a2e
RS
3521 (let ((face 'default)
3522 (position to))
043620f4 3523 (ps-print-ensure-fontified from to)
87a16a06
RS
3524 (cond
3525 ((or (eq ps-print-emacs-type 'lucid)
3526 (eq ps-print-emacs-type 'xemacs))
3527 ;; Build the list of extents...
3528 (let ((a (cons 'dummy nil))
3529 record type extent extent-list)
3530 (map-extents 'ps-mapper nil from to a)
8bd22fcf
KH
3531 (setq a (sort (cdr a) 'car-less-than-car)
3532 extent-list nil)
87a16a06
RS
3533
3534 ;; Loop through the extents...
3535 (while a
8bd22fcf 3536 (setq record (car a)
87a16a06 3537
8bd22fcf
KH
3538 position (car record)
3539 record (cdr record)
87a16a06 3540
8bd22fcf
KH
3541 type (car record)
3542 record (cdr record)
87a16a06 3543
8bd22fcf 3544 extent (car record))
87a16a06
RS
3545
3546 ;; Plot up to this record.
3547 ;; XEmacs 19.12: for some reason, we're getting into a
3548 ;; situation in which some of the records have
3549 ;; positions less than 'from'. Since we've narrowed
3550 ;; the buffer, this'll generate errors. This is a
3551 ;; hack, but don't call ps-plot-with-face unless from >
3552 ;; point-min.
8bd22fcf
KH
3553 (and (>= from (point-min)) (<= position (point-max))
3554 (ps-plot-with-face from position face))
87a16a06
RS
3555
3556 (cond
3557 ((eq type 'push)
3558 (if (extent-face extent)
3559 (setq extent-list (sort (cons extent extent-list)
3560 'ps-extent-sorter))))
3561
3562 ((eq type 'pull)
3563 (setq extent-list (sort (delq extent extent-list)
3564 'ps-extent-sorter))))
3565
3566 (setq face
3567 (if extent-list
3568 (extent-face (car extent-list))
8bd22fcf 3569 'default)
87a16a06 3570
8bd22fcf
KH
3571 from position
3572 a (cdr a)))))
87a16a06
RS
3573
3574 ((eq ps-print-emacs-type 'emacs)
3575 (let ((property-change from)
3576 (overlay-change from))
3577 (while (< from to)
3578 (if (< property-change to) ; Don't search for property change
12d89a2e 3579 ; unless previous search succeeded.
87a16a06
RS
3580 (setq property-change
3581 (next-property-change from nil to)))
3582 (if (< overlay-change to) ; Don't search for overlay change
12d89a2e 3583 ; unless previous search succeeded.
87a16a06
RS
3584 (setq overlay-change
3585 (min (next-overlay-change from) to)))
3586 (setq position
3587 (min property-change overlay-change))
3588 ;; The code below is not quite correct,
3589 ;; because a non-nil overlay invisible property
3590 ;; which is inactive according to the current value
3591 ;; of buffer-invisibility-spec nonetheless overrides
3592 ;; a face text property.
3593 (setq face
3594 (cond ((let ((prop (get-text-property from 'invisible)))
3595 ;; Decide whether this invisible property
3596 ;; really makes the text invisible.
3597 (if (eq buffer-invisibility-spec t)
3598 (not (null prop))
3599 (or (memq prop buffer-invisibility-spec)
3600 (assq prop buffer-invisibility-spec))))
3601 nil)
3602 ((get-text-property from 'face))
3603 (t 'default)))
3604 (let ((overlays (overlays-at from))
3605 (face-priority -1)) ; text-property
3606 (while overlays
3607 (let* ((overlay (car overlays))
3608 (overlay-face (overlay-get overlay 'face))
3609 (overlay-invisible (overlay-get overlay 'invisible))
3610 (overlay-priority (or (overlay-get overlay
3611 'priority)
3612 0)))
8bd22fcf
KH
3613 (and (or overlay-invisible overlay-face)
3614 (> overlay-priority face-priority)
3615 (setq face (cond ((if (eq buffer-invisibility-spec t)
3616 (not (null overlay-invisible))
3617 (or (memq overlay-invisible
3618 buffer-invisibility-spec)
3619 (assq overlay-invisible
3620 buffer-invisibility-spec)))
3621 nil)
3622 ((and face overlay-face)))
3623 face-priority overlay-priority)))
87a16a06
RS
3624 (setq overlays (cdr overlays))))
3625 ;; Plot up to this record.
3626 (ps-plot-with-face from position face)
3627 (setq from position)))))
3628 (ps-plot-with-face from to face))))
ef2cbb24
RS
3629
3630(defun ps-generate-postscript (from to)
12d89a2e 3631 (ps-plot-region from to 0 nil))
ef2cbb24
RS
3632
3633(defun ps-generate (buffer from to genfunc)
87a16a06
RS
3634 (save-excursion
3635 (let ((from (min to from))
3636 (to (max to from))
3637 ;; This avoids trouble if chars with read-only properties
3638 ;; are copied into ps-spool-buffer.
3639 (inhibit-read-only t))
3640 (save-restriction
3641 (narrow-to-region from to)
857686a6
RS
3642 (and ps-razzle-dazzle
3643 (message "Formatting...%3d%%" (setq ps-razchunk 0)))
87a16a06 3644 (set-buffer buffer)
8bd22fcf
KH
3645 (setq ps-source-buffer buffer
3646 ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
87a16a06
RS
3647 (ps-init-output-queue)
3648 (let (safe-marker completed-safely needs-begin-file)
3649 (unwind-protect
00aa16af
RS
3650 (progn
3651 (set-buffer ps-spool-buffer)
ef2cbb24 3652
87a16a06
RS
3653 ;; Get a marker and make it point to the current end of the
3654 ;; buffer, If an error occurs, we'll delete everything from
3655 ;; the end of this marker onwards.
3656 (setq safe-marker (make-marker))
3657 (set-marker safe-marker (point-max))
3658
3659 (goto-char (point-min))
8bd22fcf
KH
3660 (or (looking-at (regexp-quote ps-adobe-tag))
3661 (setq needs-begin-file t))
87a16a06
RS
3662 (save-excursion
3663 (set-buffer ps-source-buffer)
3664 (if needs-begin-file (ps-begin-file))
3665 (ps-begin-job)
3666 (ps-begin-page))
3667 (set-buffer ps-source-buffer)
3668 (funcall genfunc from to)
3669 (ps-end-page)
3670
8bd22fcf
KH
3671 (and ps-spool-duplex (= (mod ps-page-count 2) 1)
3672 (ps-dummy-page))
87a16a06
RS
3673 (ps-flush-output)
3674
3675 ;; Back to the PS output buffer to set the page count
3676 (set-buffer ps-spool-buffer)
8bd22fcf
KH
3677 (goto-char (point-min))
3678 (and (re-search-forward "^/PageCount 0 def$" nil t)
3679 (replace-match (format "/PageCount %d def" ps-page-count)
3680 t))
87a16a06
RS
3681
3682 ;; Setting this variable tells the unwind form that the
8bd22fcf 3683 ;; the PostScript was generated without error.
87a16a06
RS
3684 (setq completed-safely t))
3685
3686 ;; Unwind form: If some bad mojo occurred while generating
8bd22fcf 3687 ;; PostScript, delete all the PostScript that was generated.
87a16a06
RS
3688 ;; This protects the previously spooled files from getting
3689 ;; corrupted.
8bd22fcf
KH
3690 (and (markerp safe-marker) (not completed-safely)
3691 (progn
3692 (set-buffer ps-spool-buffer)
3693 (delete-region (marker-position safe-marker) (point-max))))))
87a16a06 3694
857686a6 3695 (and ps-razzle-dazzle (message "Formatting...done"))))))
ef2cbb24 3696
857686a6 3697;; Permit dynamic evaluation at print time of `ps-lpr-switches'.
ef2cbb24 3698(defun ps-do-despool (filename)
12d89a2e 3699 (if (or (not (boundp 'ps-spool-buffer))
bcc0d457 3700 (not (symbol-value 'ps-spool-buffer)))
12d89a2e 3701 (message "No spooled PostScript to print")
ef2cbb24 3702 (ps-end-file)
12d89a2e 3703 (ps-flush-output)
ef2cbb24
RS
3704 (if filename
3705 (save-excursion
857686a6 3706 (and ps-razzle-dazzle (message "Saving..."))
12d89a2e 3707 (set-buffer ps-spool-buffer)
ef2cbb24
RS
3708 (setq filename (expand-file-name filename))
3709 (write-region (point-min) (point-max) filename)
857686a6 3710 (and ps-razzle-dazzle (message "Wrote %s" filename)))
ef2cbb24 3711 ;; Else, spool to the printer
857686a6 3712 (and ps-razzle-dazzle (message "Printing..."))
ef2cbb24 3713 (save-excursion
12d89a2e 3714 (set-buffer ps-spool-buffer)
87a16a06
RS
3715 (if (and (eq system-type 'ms-dos)
3716 (stringp (symbol-value 'dos-ps-printer)))
3717 (write-region (point-min) (point-max)
3718 (symbol-value 'dos-ps-printer) t 0)
62901aee
RS
3719 (let ((binary-process-input t)) ; for MS-DOS
3720 (apply 'call-process-region
3721 (point-min) (point-max) ps-lpr-command nil
857686a6 3722 (and (fboundp 'start-process) 0)
62901aee 3723 nil
857686a6
RS
3724 (ps-flatten-list ; dynamic evaluation
3725 (mapcar 'ps-eval-switch ps-lpr-switches))))))
3726 (and ps-razzle-dazzle (message "Printing...done")))
12d89a2e
RS
3727 (kill-buffer ps-spool-buffer)))
3728
857686a6
RS
3729;; Dynamic evaluation
3730(defun ps-eval-switch (arg)
3731 (cond ((stringp arg) arg)
3732 ((functionp arg) (apply arg nil))
3733 ((symbolp arg) (symbol-value arg))
3734 ((consp arg) (apply (car arg) (cdr arg)))
3735 (t nil)))
3736
3737;; `ps-flatten-list' is defined here (copied from "message.el" and
3738;; enhanced to handle dotted pairs as well) until we can get some
3739;; sensible autoloads, or `flatten-list' gets put somewhere decent.
3740
3741;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
3742;; => (a b c d e f g h i j)
3743
3744(defun ps-flatten-list (&rest list)
3745 (ps-flatten-list-1 list))
3746
3747(defun ps-flatten-list-1 (list)
3748 (cond ((null list) nil)
3749 ((consp list) (append (ps-flatten-list-1 (car list))
3750 (ps-flatten-list-1 (cdr list))))
3751 (t (list list))))
3752
12d89a2e
RS
3753(defun ps-kill-emacs-check ()
3754 (let (ps-buffer)
8bd22fcf
KH
3755 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
3756 (buffer-modified-p ps-buffer)
3757 (y-or-n-p "Unprinted PostScript waiting; print now? ")
3758 (ps-despool))
3759 (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
3760 (buffer-modified-p ps-buffer)
3761 (not (yes-or-no-p "Unprinted PostScript waiting; exit anyway? "))
3762 (error "Unprinted PostScript"))))
12d89a2e
RS
3763
3764(if (fboundp 'add-hook)
bcc0d457 3765 (funcall 'add-hook 'kill-emacs-hook 'ps-kill-emacs-check)
12d89a2e
RS
3766 (if kill-emacs-hook
3767 (message "Won't override existing kill-emacs-hook")
3768 (setq kill-emacs-hook 'ps-kill-emacs-check)))
ef2cbb24 3769
12d89a2e 3770;;; Sample Setup Code:
ef2cbb24 3771
12d89a2e 3772;; This stuff is for anybody that's brave enough to look this far,
87a16a06
RS
3773;; and able to figure out how to use it. It isn't really part of
3774;; ps-print, but I'll leave it here in hopes it might be useful:
ef2cbb24 3775
043620f4
KH
3776;; WARNING!!! The following code is *sample* code only. Don't use it
3777;; unless you understand what it does!
3778
87a16a06
RS
3779(defmacro ps-prsc ()
3780 `(if (eq ps-print-emacs-type 'emacs) [f22] 'f22))
3781(defmacro ps-c-prsc ()
3782 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
3783(defmacro ps-s-prsc ()
3784 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
00aa16af 3785
a18ed129
RS
3786;; A hook to bind to `rmail-mode-hook' to locally bind prsc and set the
3787;; `ps-left-headers' specially for mail messages.
3788(defun ps-rmail-mode-hook ()
3789 (local-set-key (ps-prsc) 'ps-rmail-print-message-from-summary)
3790 (setq ps-header-lines 3
3791 ps-left-header
3792 ;; The left headers will display the message's subject, its
3793 ;; author, and the name of the folder it was in.
3794 '(ps-article-subject ps-article-author buffer-name)))
3795
3796;; See `ps-gnus-print-article-from-summary'. This function does the
3797;; same thing for rmail.
3798(defun ps-rmail-print-message-from-summary ()
3799 (interactive)
3800 (ps-print-message-from-summary 'rmail-summary-buffer "RMAIL"))
3801
3802;; Used in `ps-rmail-print-article-from-summary',
3803;; `ps-gnus-print-article-from-summary' and `ps-vm-print-message-from-summary'.
3804(defun ps-print-message-from-summary (summary-buffer summary-default)
3805 (let ((ps-buf (or (and (boundp summary-buffer)
3806 (symbol-value summary-buffer))
3807 summary-default)))
3808 (and (get-buffer ps-buf)
3809 (save-excursion
3810 (set-buffer ps-buf)
3811 (ps-spool-buffer-with-faces)))))
3812
12d89a2e 3813;; Look in an article or mail message for the Subject: line. To be
87a16a06 3814;; placed in `ps-left-headers'.
12d89a2e 3815(defun ps-article-subject ()
ef2cbb24 3816 (save-excursion
12d89a2e 3817 (goto-char (point-min))
45a870d9 3818 (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
055e7bf2 3819 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
12d89a2e
RS
3820 "Subject ???")))
3821
3822;; Look in an article or mail message for the From: line. Sorta-kinda
3823;; understands RFC-822 addresses and can pull the real name out where
87a16a06 3824;; it's provided. To be placed in `ps-left-headers'.
12d89a2e
RS
3825(defun ps-article-author ()
3826 (save-excursion
3827 (goto-char (point-min))
a97592dd 3828 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
87a16a06
RS
3829 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
3830 (match-end 1))))
12d89a2e
RS
3831 (cond
3832
3833 ;; Try first to match addresses that look like
3834 ;; thompson@wg2.waii.com (Jim Thompson)
3835 ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
3836 (substring fromstring (match-beginning 1) (match-end 1)))
3837
3838 ;; Next try to match addresses that look like
3839 ;; Jim Thompson <thompson@wg2.waii.com>
3840 ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
3841 (substring fromstring (match-beginning 1) (match-end 1)))
3842
3843 ;; Couldn't find a real name -- show the address instead.
3844 (t fromstring)))
3845 "From ???")))
3846
a18ed129 3847;; A hook to bind to `gnus-article-prepare-hook'. This will set the
87a16a06
RS
3848;; `ps-left-headers' specially for gnus articles. Unfortunately,
3849;; `gnus-article-mode-hook' is called only once, the first time the *Article*
12d89a2e
RS
3850;; buffer enters that mode, so it would only work for the first time
3851;; we ran gnus. The second time, this hook wouldn't get set up. The
87a16a06 3852;; only alternative is `gnus-article-prepare-hook'.
12d89a2e 3853(defun ps-gnus-article-prepare-hook ()
8bd22fcf
KH
3854 (setq ps-header-lines 3
3855 ps-left-header
12d89a2e
RS
3856 ;; The left headers will display the article's subject, its
3857 ;; author, and the newsgroup it was in.
8bd22fcf 3858 '(ps-article-subject ps-article-author gnus-newsgroup-name)))
12d89a2e 3859
a18ed129
RS
3860;; A hook to bind to `vm-mode-hook' to locally bind prsc and set the
3861;; `ps-left-headers' specially for mail messages.
12d89a2e 3862(defun ps-vm-mode-hook ()
00aa16af 3863 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
8bd22fcf
KH
3864 (setq ps-header-lines 3
3865 ps-left-header
12d89a2e
RS
3866 ;; The left headers will display the message's subject, its
3867 ;; author, and the name of the folder it was in.
8bd22fcf 3868 '(ps-article-subject ps-article-author buffer-name)))
12d89a2e
RS
3869
3870;; Every now and then I forget to switch from the *Summary* buffer to
3871;; the *Article* before hitting prsc, and a nicely formatted list of
3872;; article subjects shows up at the printer. This function, bound to
3873;; prsc for the gnus *Summary* buffer means I don't have to switch
3874;; buffers first.
87a16a06 3875;; sb: Updated for Gnus 5.
12d89a2e
RS
3876(defun ps-gnus-print-article-from-summary ()
3877 (interactive)
a18ed129 3878 (ps-print-message-from-summary 'gnus-article-buffer "*Article*"))
ef2cbb24 3879
87a16a06 3880;; See `ps-gnus-print-article-from-summary'. This function does the
12d89a2e
RS
3881;; same thing for vm.
3882(defun ps-vm-print-message-from-summary ()
3883 (interactive)
a18ed129 3884 (ps-print-message-from-summary 'vm-mail-buffer ""))
ef2cbb24 3885
87a16a06 3886;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
12d89a2e
RS
3887;; prsc.
3888(defun ps-gnus-summary-setup ()
00aa16af 3889 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
12d89a2e
RS
3890
3891;; Look in an article or mail message for the Subject: line. To be
87a16a06 3892;; placed in `ps-left-headers'.
12d89a2e
RS
3893(defun ps-info-file ()
3894 (save-excursion
3895 (goto-char (point-min))
a97592dd 3896 (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
055e7bf2 3897 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
12d89a2e
RS
3898 "File ???")))
3899
3900;; Look in an article or mail message for the Subject: line. To be
87a16a06 3901;; placed in `ps-left-headers'.
12d89a2e
RS
3902(defun ps-info-node ()
3903 (save-excursion
3904 (goto-char (point-min))
a97592dd 3905 (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
055e7bf2 3906 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
12d89a2e
RS
3907 "Node ???")))
3908
3909(defun ps-info-mode-hook ()
3910 (setq ps-left-header
3911 ;; The left headers will display the node name and file name.
8bd22fcf 3912 '(ps-info-node ps-info-file)))
12d89a2e 3913
043620f4
KH
3914;; WARNING! The following function is a *sample* only, and is *not*
3915;; meant to be used as a whole unless you understand what the effects
87a16a06
RS
3916;; will be! (In fact, this is a copy of Jim's setup for ps-print --
3917;; I'd be very surprised if it was useful to *anybody*, without
043620f4
KH
3918;; modification.)
3919
12d89a2e 3920(defun ps-jts-ps-setup ()
00aa16af
RS
3921 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
3922 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
3923 (global-set-key (ps-c-prsc) 'ps-despool)
12d89a2e
RS
3924 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
3925 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
3926 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
00aa16af 3927 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
12d89a2e 3928 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
8bd22fcf
KH
3929 (setq ps-spool-duplex t
3930 ps-print-color-p nil
3931 ps-lpr-command "lpr"
3932 ps-lpr-switches '("-Jjct,duplex_long"))
bcc0d457
RS
3933 'ps-jts-ps-setup)
3934
3935;; WARNING! The following function is a *sample* only, and is *not*
3936;; meant to be used as a whole unless it corresponds to your needs.
3937;; (In fact, this is a copy of Jack's setup for ps-print --
3938;; I would not be that surprised if it was useful to *anybody*,
3939;; without modification.)
3940
3941(defun ps-jack-setup ()
87a16a06 3942 (setq ps-print-color-p nil
bcc0d457 3943 ps-lpr-command "lpr"
8bd22fcf 3944 ps-lpr-switches nil
bcc0d457 3945
87a16a06
RS
3946 ps-paper-type 'a4
3947 ps-landscape-mode t
bcc0d457
RS
3948 ps-number-of-columns 2
3949
3950 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
3951 ps-right-margin (/ (* 72 1.0) 2.54) ; 1.0 cm
3952 ps-inter-column (/ (* 72 1.0) 2.54) ; 1.0 cm
3953 ps-bottom-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
3954 ps-top-margin (/ (* 72 1.5) 2.54) ; 1.5 cm
3955 ps-header-offset (/ (* 72 1.0) 2.54) ; 1.0 cm
3956 ps-header-line-pad .15
3957 ps-print-header t
3958 ps-print-header-frame t
3959 ps-header-lines 2
3960 ps-show-n-of-n t
3961 ps-spool-duplex nil
3962
3963 ps-font-family 'Courier
3964 ps-font-size 5.5
3965 ps-header-font-family 'Helvetica
3966 ps-header-font-size 6
3967 ps-header-title-font-size 8)
3968 'ps-jack-setup)
12d89a2e
RS
3969
3970(provide 'ps-print)
b87c5d3d 3971
12d89a2e 3972;;; ps-print.el ends here