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