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