Mercurial > emacs
comparison lisp/ps-print.el @ 19879:87952270ceeb
(ps-emacs-face-kind-p): Function deleted.
(ps-face-bold-p, ps-face-italic-p):
Check ps-bold-faces or ps-italic-faces.
(ps-zebra-stripes, ps-zebra-stripe-height): Doc fixes.
(ps-line-lengths, ps-nb-pages-buffer, ps-nb-pages-region, ps-setup): Doc fixes.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 11 Sep 1997 23:51:29 +0000 |
parents | 0c9342c1054d |
children | d8e290881d8c |
comparison
equal
deleted
inserted
replaced
19878:a69ae37e6932 | 19879:87952270ceeb |
---|---|
97 ;; The spooling mechanism was designed for printing lots of small | 97 ;; The spooling mechanism was designed for printing lots of small |
98 ;; files (mail messages or netnews articles) to save paper that would | 98 ;; files (mail messages or netnews articles) to save paper that would |
99 ;; otherwise be wasted on banner pages, and to make it easier to find | 99 ;; otherwise be wasted on banner pages, and to make it easier to find |
100 ;; your output at the printer (it's easier to pick up one 50-page | 100 ;; your output at the printer (it's easier to pick up one 50-page |
101 ;; printout than to find 50 single-page printouts). | 101 ;; printout than to find 50 single-page printouts). |
102 ;; | 102 ;; |
103 ;; Ps-print has a hook in the `kill-emacs-hooks' so that you won't | 103 ;; Ps-print has a hook in the `kill-emacs-hooks' so that you won't |
104 ;; accidentally quit from Emacs while you have unprinted PostScript | 104 ;; accidentally quit from Emacs while you have unprinted PostScript |
105 ;; waiting in the spool buffer. If you do attempt to exit with | 105 ;; waiting in the spool buffer. If you do attempt to exit with |
106 ;; spooled PostScript, you'll be asked if you want to print it, and if | 106 ;; spooled PostScript, you'll be asked if you want to print it, and if |
107 ;; you decline, you'll be asked to confirm the exit; this is modeled | 107 ;; you decline, you'll be asked to confirm the exit; this is modeled |
274 ;; directory; on the right, the page number and date of printing. | 274 ;; directory; on the right, the page number and date of printing. |
275 ;; The default headers look something like this: | 275 ;; The default headers look something like this: |
276 ;; | 276 ;; |
277 ;; ps-print.el 1/21 | 277 ;; ps-print.el 1/21 |
278 ;; /home/jct/emacs-lisp/ps/new 94/12/31 | 278 ;; /home/jct/emacs-lisp/ps/new 94/12/31 |
279 ;; | 279 ;; |
280 ;; When printing on duplex printers, left and right are reversed so | 280 ;; When printing on duplex printers, left and right are reversed so |
281 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex'). | 281 ;; that the page numbers are toward the outside (cf. `ps-spool-duplex'). |
282 ;; | 282 ;; |
283 ;; Headers are configurable: | 283 ;; Headers are configurable: |
284 ;; To turn them off completely, set `ps-print-header' to nil. | 284 ;; To turn them off completely, set `ps-print-header' to nil. |
285 ;; To turn off the header's gaudy framing box, | 285 ;; To turn off the header's gaudy framing box, |
286 ;; set `ps-print-header-frame' to nil. | 286 ;; set `ps-print-header-frame' to nil. |
287 ;; | 287 ;; |
288 ;; The font family and size of text in the header are determined | 288 ;; The font family and size of text in the header are determined |
289 ;; by the variables `ps-header-font-family', `ps-header-font-size' and | 289 ;; by the variables `ps-header-font-family', `ps-header-font-size' and |
290 ;; `ps-header-title-font-size' (see below). | 290 ;; `ps-header-title-font-size' (see below). |
291 ;; | 291 ;; |
292 ;; The variable `ps-header-line-pad' determines the portion of a header | 292 ;; The variable `ps-header-line-pad' determines the portion of a header |
293 ;; title line height to insert between the header frame and the text | 293 ;; title line height to insert between the header frame and the text |
294 ;; it contains, both in the vertical and horizontal directions: | 294 ;; it contains, both in the vertical and horizontal directions: |
359 ;; Ps-print will insert blank pages to make sure each buffer starts | 359 ;; Ps-print will insert blank pages to make sure each buffer starts |
360 ;; on the correct side of the paper. | 360 ;; on the correct side of the paper. |
361 ;; Don't forget to set `ps-lpr-switches' to select duplex printing | 361 ;; Don't forget to set `ps-lpr-switches' to select duplex printing |
362 ;; for your printer. | 362 ;; for your printer. |
363 ;; | 363 ;; |
364 ;; | 364 ;; |
365 ;; Line Number | 365 ;; Line Number |
366 ;; ----------- | 366 ;; ----------- |
367 ;; | 367 ;; |
368 ;; The variable `ps-line-number' specifies whether to number each line; | 368 ;; The variable `ps-line-number' specifies whether to number each line; |
369 ;; non-nil means do so. The default is nil (don't number each line). | 369 ;; non-nil means do so. The default is nil (don't number each line). |
383 ;; | 383 ;; |
384 ;; XXXXXXXXXXXXXXXXXXXXXXXX | 384 ;; XXXXXXXXXXXXXXXXXXXXXXXX |
385 ;; XXXXXXXXXXXXXXXXXXXXXXXX | 385 ;; XXXXXXXXXXXXXXXXXXXXXXXX |
386 ;; XXXXXXXXXXXXXXXXXXXXXXXX | 386 ;; XXXXXXXXXXXXXXXXXXXXXXXX |
387 ;; | 387 ;; |
388 ;; The X's here represent rectangles filled with a light gray color. | 388 ;; The blocks of X's represent rectangles filled with a light gray color. |
389 ;; Each rectangle extends all the way across the page. | 389 ;; Each rectangle extends all the way across the page. |
390 ;; | 390 ;; |
391 ;; The height, in lines, of each rectangle is controlled by | 391 ;; The height, in lines, of each rectangle is controlled by |
392 ;; the variable `ps-zebra-stripe-height', which is 3 by default. | 392 ;; the variable `ps-zebra-stripe-height', which is 3 by default. |
393 ;; The distance between stripes equals the height of a stripe. | 393 ;; The distance between stripes equals the height of a stripe. |
406 ;; for a list of font families (currently mainly `Courier' `Helvetica' | 406 ;; for a list of font families (currently mainly `Courier' `Helvetica' |
407 ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk'). | 407 ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk'). |
408 ;; Each font family contains the font names for standard, bold, italic | 408 ;; Each font family contains the font names for standard, bold, italic |
409 ;; and bold-italic characters, a reference size (usually 10) and the | 409 ;; and bold-italic characters, a reference size (usually 10) and the |
410 ;; corresponding line height, width of a space and average character width. | 410 ;; corresponding line height, width of a space and average character width. |
411 ;; | 411 ;; |
412 ;; The variable `ps-font-family' determines which font family | 412 ;; The variable `ps-font-family' determines which font family |
413 ;; is to be used for ordinary text. | 413 ;; is to be used for ordinary text. |
414 ;; If its value does not correspond to a known font family, | 414 ;; If its value does not correspond to a known font family, |
415 ;; an error message is printed into the `*Messages*' buffer, | 415 ;; an error message is printed into the `*Messages*' buffer, |
416 ;; which lists the currently available font families. | 416 ;; which lists the currently available font families. |
544 ;; overline - like underline, but the line is over the text. | 544 ;; overline - like underline, but the line is over the text. |
545 ;; shadow - text will have a shadow. | 545 ;; shadow - text will have a shadow. |
546 ;; box - text will be surrounded by a box. | 546 ;; box - text will be surrounded by a box. |
547 ;; outline - print characters as hollow outlines. | 547 ;; outline - print characters as hollow outlines. |
548 ;; | 548 ;; |
549 ;; See the documentation for `ps-extend-face' and `ps-extend-face-list'. | 549 ;; See the documentation for `ps-extend-face'. |
550 ;; | 550 ;; |
551 ;; Let's, for example, remap font-lock-keyword-face to another foreground color | 551 ;; Let's, for example, remap font-lock-keyword-face to another foreground color |
552 ;; and bold attribute: | 552 ;; and bold attribute: |
553 ;; | 553 ;; |
554 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE) | 554 ;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold) 'MERGE) |
555 ;; | 555 ;; |
556 ;; If you want to use a new face, define it first with `defface', | 556 ;; If you want to use a new face, define it first with `defface', |
557 ;; and then call `ps-extend-face' to specify how to print it. | 557 ;; and then call `ps-extend-face' to specify how to print it. |
558 ;; | |
559 ;; NOTE: the only face attributes that have an effect are bold, italic and | |
560 ;; underline. All other attributes are ignored. | |
561 ;; | 558 ;; |
562 ;; | 559 ;; |
563 ;; How Ps-Print Has A Text And/Or Image On Background | 560 ;; How Ps-Print Has A Text And/Or Image On Background |
564 ;; -------------------------------------------------- | 561 ;; -------------------------------------------------- |
565 ;; | 562 ;; |
694 ;; | 691 ;; |
695 ;; Faces are always treated as opaque. | 692 ;; Faces are always treated as opaque. |
696 ;; | 693 ;; |
697 ;; Epoch and Emacs 18 not supported. At all. | 694 ;; Epoch and Emacs 18 not supported. At all. |
698 ;; | 695 ;; |
699 ;; Fixed-pitch fonts work better for line folding, but are not required. | 696 ;; Fixed-pitch fonts work better for line folding, but are not required. |
700 ;; | 697 ;; |
701 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care | 698 ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care |
702 ;; of folding lines. | 699 ;; of folding lines. |
703 ;; | 700 ;; |
704 ;; | 701 ;; |
871 :type 'number | 868 :type 'number |
872 :group 'ps-print) | 869 :group 'ps-print) |
873 | 870 |
874 (defcustom ps-zebra-stripes nil | 871 (defcustom ps-zebra-stripes nil |
875 "*Non-nil means print zebra stripes. | 872 "*Non-nil means print zebra stripes. |
876 See also documentation for `ps-print-n-zebra'." | 873 See also documentation for `ps-zebra-stripe-height'." |
877 :type 'boolean | 874 :type 'boolean |
878 :group 'ps-print) | 875 :group 'ps-print) |
879 | 876 |
880 (defcustom ps-zebra-stripe-height 3 | 877 (defcustom ps-zebra-stripe-height 3 |
881 "*Number of zebra stripe lines. | 878 "*Number of zebra stripe lines. |
882 See also documentation for `ps-print-zebra'." | 879 See also documentation for `ps-zebra-stripes'." |
883 :type 'number | 880 :type 'number |
884 :group 'ps-print) | 881 :group 'ps-print) |
885 | 882 |
886 (defcustom ps-line-number nil | 883 (defcustom ps-line-number nil |
887 "*Non-nil means print line number." | 884 "*Non-nil means print line number." |
1394 (interactive (list (ps-print-preprint current-prefix-arg))) | 1391 (interactive (list (ps-print-preprint current-prefix-arg))) |
1395 (ps-do-despool filename)) | 1392 (ps-do-despool filename)) |
1396 | 1393 |
1397 ;;;###autoload | 1394 ;;;###autoload |
1398 (defun ps-line-lengths () | 1395 (defun ps-line-lengths () |
1399 "*Display the correspondence between a line length and a font size, | 1396 "Display the correspondence between a line length and a font size, |
1400 using the current ps-print setup. | 1397 using the current ps-print setup. |
1401 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head" | 1398 Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head" |
1402 (interactive) | 1399 (interactive) |
1403 (ps-line-lengths-internal)) | 1400 (ps-line-lengths-internal)) |
1404 | 1401 |
1405 ;;;###autoload | 1402 ;;;###autoload |
1406 (defun ps-nb-pages-buffer (nb-lines) | 1403 (defun ps-nb-pages-buffer (nb-lines) |
1407 "*Display an approximate correspondence between a font size and the number | 1404 "Display number of pages to print this buffer, for various font heights. |
1408 of pages the current buffer would require to print | 1405 The table depends on the current ps-print setup." |
1409 using the current ps-print setup." | |
1410 (interactive (list (count-lines (point-min) (point-max)))) | 1406 (interactive (list (count-lines (point-min) (point-max)))) |
1411 (ps-nb-pages nb-lines)) | 1407 (ps-nb-pages nb-lines)) |
1412 | 1408 |
1413 ;;;###autoload | 1409 ;;;###autoload |
1414 (defun ps-nb-pages-region (nb-lines) | 1410 (defun ps-nb-pages-region (nb-lines) |
1415 "*Display an approximate correspondence between a font size and the number | 1411 "Display number of pages to print the region, for various font heights. |
1416 of pages the current region would require to print | 1412 The table depends on the current ps-print setup." |
1417 using the current ps-print setup." | |
1418 (interactive (list (count-lines (mark) (point)))) | 1413 (interactive (list (count-lines (mark) (point)))) |
1419 (ps-nb-pages nb-lines)) | 1414 (ps-nb-pages nb-lines)) |
1420 | 1415 |
1421 ;;;###autoload | 1416 ;;;###autoload |
1422 (defun ps-setup () | 1417 (defun ps-setup () |
1423 "*Return the current setup" | 1418 "Return the current setup." |
1424 (format | 1419 (format |
1425 " | 1420 " |
1426 \(setq ps-print-color-p %s | 1421 \(setq ps-print-color-p %s |
1427 ps-lpr-command \"%s\" | 1422 ps-lpr-command \"%s\" |
1428 ps-lpr-switches %s | 1423 ps-lpr-switches %s |
2681 (error "Could not read file `%s'" fname)) | 2676 (error "Could not read file `%s'" fname)) |
2682 (save-excursion | 2677 (save-excursion |
2683 (set-buffer ps-spool-buffer) | 2678 (set-buffer ps-spool-buffer) |
2684 (goto-char (point-max)) | 2679 (goto-char (point-max)) |
2685 (insert-file fname))) | 2680 (insert-file fname))) |
2686 | 2681 |
2687 ;; These functions insert the arrays that define the contents of the | 2682 ;; These functions insert the arrays that define the contents of the |
2688 ;; headers. | 2683 ;; headers. |
2689 | 2684 |
2690 (defun ps-generate-header-line (fonttag &optional content) | 2685 (defun ps-generate-header-line (fonttag &optional content) |
2691 (ps-output " [ " fonttag " ") | 2686 (ps-output " [ " fonttag " ") |
2721 (setq count (+ count 1))) | 2716 (setq count (+ count 1))) |
2722 (ps-output "] def\n")))) | 2717 (ps-output "] def\n")))) |
2723 | 2718 |
2724 (defun ps-output-boolean (name bool) | 2719 (defun ps-output-boolean (name bool) |
2725 (ps-output (format "/%s %s def\n" name (if bool "true" "false")))) | 2720 (ps-output (format "/%s %s def\n" name (if bool "true" "false")))) |
2721 | |
2726 | 2722 |
2727 (defun ps-background-pages (page-list func) | 2723 (defun ps-background-pages (page-list func) |
2728 (if page-list | 2724 (if page-list |
2729 (mapcar | 2725 (mapcar |
2730 '(lambda (pages) | 2726 '(lambda (pages) |
2890 | 2886 |
2891 (ps-output (format "/BottomMargin %s def\n" ps-bottom-margin)) | 2887 (ps-output (format "/BottomMargin %s def\n" ps-bottom-margin)) |
2892 (ps-output (format "/TopMargin %s def\n" ps-top-margin)) ; not used | 2888 (ps-output (format "/TopMargin %s def\n" ps-top-margin)) ; not used |
2893 (ps-output (format "/HeaderOffset %s def\n" ps-header-offset)) | 2889 (ps-output (format "/HeaderOffset %s def\n" ps-header-offset)) |
2894 (ps-output (format "/HeaderPad %s def\n" ps-header-pad)) | 2890 (ps-output (format "/HeaderPad %s def\n" ps-header-pad)) |
2895 | 2891 |
2896 (ps-output-boolean "PrintHeader" ps-print-header) | 2892 (ps-output-boolean "PrintHeader" ps-print-header) |
2897 (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame) | 2893 (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame) |
2898 (ps-output-boolean "ShowNofN" ps-show-n-of-n) | 2894 (ps-output-boolean "ShowNofN" ps-show-n-of-n) |
2899 (ps-output-boolean "Duplex" ps-spool-duplex) | 2895 (ps-output-boolean "Duplex" ps-spool-duplex) |
2900 | 2896 |
3016 (ps-header-page t) | 3012 (ps-header-page t) |
3017 (ps-output "/PrintHeader false def | 3013 (ps-output "/PrintHeader false def |
3018 BeginPage | 3014 BeginPage |
3019 EndPage | 3015 EndPage |
3020 EndDSCPage\n")) | 3016 EndDSCPage\n")) |
3021 | 3017 |
3022 (defun ps-next-line () | 3018 (defun ps-next-line () |
3023 (setq ps-showline-count (1+ ps-showline-count)) | 3019 (setq ps-showline-count (1+ ps-showline-count)) |
3024 (if (< ps-height-remaining ps-line-height) | 3020 (if (< ps-height-remaining ps-line-height) |
3025 (ps-next-page) | 3021 (ps-next-page) |
3026 (setq ps-width-remaining ps-print-width) | 3022 (setq ps-width-remaining ps-print-width) |
3108 | 3104 |
3109 | 3105 |
3110 (defun ps-plot-region (from to font &optional fg-color bg-color effects) | 3106 (defun ps-plot-region (from to font &optional fg-color bg-color effects) |
3111 (if (not (equal font ps-current-font)) | 3107 (if (not (equal font ps-current-font)) |
3112 (ps-set-font font)) | 3108 (ps-set-font font)) |
3113 | 3109 |
3114 ;; Specify a foreground color only if one's specified and it's | 3110 ;; Specify a foreground color only if one's specified and it's |
3115 ;; different than the current. | 3111 ;; different than the current. |
3116 (if (not (equal fg-color ps-current-color)) | 3112 (if (not (equal fg-color ps-current-color)) |
3117 (ps-set-color fg-color)) | 3113 (ps-set-color fg-color)) |
3118 | 3114 |
3119 (if (not (equal bg-color ps-current-bg)) | 3115 (if (not (equal bg-color ps-current-bg)) |
3120 (ps-set-bg bg-color)) | 3116 (ps-set-bg bg-color)) |
3121 | 3117 |
3122 ;; Specify effects (underline, overline, box, etc) | 3118 ;; Specify effects (underline, overline, box, etc) |
3123 (cond | 3119 (cond |
3124 ((not (integerp effects)) | 3120 ((not (integerp effects)) |
3125 (ps-output "0 EF\n") | 3121 (ps-output "0 EF\n") |
3126 (setq ps-current-effect 0)) | 3122 (setq ps-current-effect 0)) |
3245 fg-color bg-color (lsh effect -2))) | 3241 fg-color bg-color (lsh effect -2))) |
3246 (ps-plot-region from to 0)) | 3242 (ps-plot-region from to 0)) |
3247 (goto-char to)) | 3243 (goto-char to)) |
3248 | 3244 |
3249 | 3245 |
3250 (defun ps-emacs-face-kind-p (face kind kind-regex kind-list) | |
3251 (let ((frame-font (face-font face)) | |
3252 (face-defaults (face-font face t))) | |
3253 (or | |
3254 ;; Check FACE defaults: | |
3255 (and (listp face-defaults) | |
3256 (memq kind face-defaults)) | |
3257 ;; Check the user's preferences | |
3258 (memq face kind-list)))) | |
3259 | |
3260 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list) | 3246 (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list) |
3261 (let* ((frame-font (or (face-font face) (face-font 'default))) | 3247 (let* ((frame-font (or (face-font face) (face-font 'default))) |
3262 (kind-cons (assq kind (x-font-properties frame-font))) | 3248 (kind-cons (assq kind (x-font-properties frame-font))) |
3263 (kind-spec (cdr-safe kind-cons)) | 3249 (kind-spec (cdr-safe kind-cons)) |
3264 (case-fold-search t)) | 3250 (case-fold-search t)) |
3267 ;; Kludge-compatible: | 3253 ;; Kludge-compatible: |
3268 (memq face kind-list)))) | 3254 (memq face kind-list)))) |
3269 | 3255 |
3270 (defun ps-face-bold-p (face) | 3256 (defun ps-face-bold-p (face) |
3271 (if (eq ps-print-emacs-type 'emacs) | 3257 (if (eq ps-print-emacs-type 'emacs) |
3272 (face-bold-p face) | 3258 (or (face-bold-p face) |
3259 (memq face ps-bold-faces)) | |
3273 (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold" | 3260 (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold" |
3274 ps-bold-faces))) | 3261 ps-bold-faces))) |
3275 | 3262 |
3276 (defun ps-face-italic-p (face) | 3263 (defun ps-face-italic-p (face) |
3277 (if (eq ps-print-emacs-type 'emacs) | 3264 (if (eq ps-print-emacs-type 'emacs) |
3278 (face-italic-p face) | 3265 (or (face-italic-p face) |
3266 (memq face ps-italic-faces)) | |
3279 (or | 3267 (or |
3280 (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces) | 3268 (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces) |
3281 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces)))) | 3269 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces)))) |
3282 | 3270 |
3283 (defun ps-face-underlined-p (face) | 3271 (defun ps-face-underlined-p (face) |
3337 (face-background face)))) | 3325 (face-background face)))) |
3338 | 3326 |
3339 | 3327 |
3340 (defun ps-mapper (extent list) | 3328 (defun ps-mapper (extent list) |
3341 (nconc list (list (list (extent-start-position extent) 'push extent) | 3329 (nconc list (list (list (extent-start-position extent) 'push extent) |
3342 (list (extent-end-position extent) 'pull extent))) | 3330 (list (extent-end-position extent) 'pull extent))) |
3343 nil) | 3331 nil) |
3344 | 3332 |
3345 (defun ps-extent-sorter (a b) | 3333 (defun ps-extent-sorter (a b) |
3346 (< (extent-priority a) (extent-priority b))) | 3334 (< (extent-priority a) (extent-priority b))) |
3347 | 3335 |
3348 (defun ps-print-ensure-fontified (start end) | 3336 (defun ps-print-ensure-fontified (start end) |
3349 (if (and (boundp 'lazy-lock-mode) lazy-lock-mode) | 3337 (if (and (boundp 'lazy-lock-mode) lazy-lock-mode) |
3350 (if (fboundp 'lazy-lock-fontify-region) | 3338 (if (fboundp 'lazy-lock-fontify-region) |
3351 (lazy-lock-fontify-region start end) ; the new | 3339 (lazy-lock-fontify-region start end) ; the new |
3352 (lazy-lock-fontify-buffer)))) ; the old | 3340 (lazy-lock-fontify-buffer)))) ; the old |
3353 | 3341 |
3354 (defun ps-generate-postscript-with-faces (from to) | 3342 (defun ps-generate-postscript-with-faces (from to) |
3355 ;; Some initialization... | 3343 ;; Some initialization... |
3356 (setq ps-current-effect 0) | 3344 (setq ps-current-effect 0) |
3357 | 3345 |