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