comparison lisp/ps-print.el @ 10683:64e6021d0ba0

Various changes.
author Richard M. Stallman <rms@gnu.org>
date Tue, 07 Feb 1995 22:51:35 +0000
parents ed52763e77d6
children e7d5b119b583
comparison
equal deleted inserted replaced
10682:5659c0885145 10683:64e6021d0ba0
1 ;;; ps-print.el --- Jim's Pretty-Good PostScript Generator for Emacs 19. 1 ;;; ps-print.el --- Jim's Pretty-Good PostScript Generator for Emacs 19.
2 2
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4 4
5 ;; Author: Jim Thompson <thompson@wg2.waii.com> 5 ;; Author: Jim Thompson <thompson@wg2.waii.com>
6 ;; Version: Jim's last version is 1.10 6 ;; Thompson's last version: 1.14
7 ;; Keywords: print, PostScript 7 ;; Keywords: print, PostScript
8 8
9 ;; This file is part of GNU Emacs. 9 ;; This file is part of GNU Emacs.
10 10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;; GNU General Public License for more details. 19 ;; GNU General Public License for more details.
20 20
21 ;; You should have received a copy of the GNU General Public License 21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to 22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;; LCD Archive Entry:
26 ;; ps-print|James C. Thompson|thompson@wg2.waii.com|
27 ;; Jim's Pretty-Good PostScript Generator for Emacs 19 (ps-print)|
28 ;; 26-Feb-1994|1.6|~/packages/ps-print.el|
24 29
25 ;;; Commentary: 30 ;;; Commentary:
26 31
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; 33 ;;
29 ;; About ps-print 34 ;; About ps-print
30 ;; -------------- 35 ;; --------------
31 ;; This package provides printing of Emacs buffers on PostScript 36 ;; This package provides printing of Emacs buffers on PostScript
32 ;; printers; the buffer's bold and italic text attributes are 37 ;; printers; the buffer's bold and italic text attributes are
33 ;; preserved in the printer output. Ps-print is intended for use with 38 ;; preserved in the printer output. Ps-print is intended for use with
34 ;; Emacs 19 (Lucid or FSF) and a fontifying package such as font-lock 39 ;; Emacs 19 or Lucid Emacs, together with a fontifying package such as
35 ;; or hilit. 40 ;; font-lock or hilit.
36 ;; 41 ;;
37 ;; Installing ps-print 42 ;; Installing ps-print
38 ;; ------------------- 43 ;; -------------------
39 ;; 44 ;;
40 ;; 1. Place ps-print.el somewhere in your load-path and byte-compile 45 ;; Make sure that the variables ps-lpr-command and ps-lpr-switches
41 ;; it. You can ignore all byte-compiler warnings; they are the 46 ;; contain appropriate values for your system; see the usage notes
42 ;; result of multi-Emacs support. This step is necessary only if 47 ;; below and the documentation of these variables.
43 ;; you're installing your own ps-print; if ps-print came with your
44 ;; copy of Emacs, this been done already.
45 ;;
46 ;; 2. Place in your .emacs file the line
47 ;;
48 ;; (require 'ps-print)
49 ;;
50 ;; to load ps-print. Or you may cause any of the ps-print commands
51 ;; to be autoloaded with an autoload command such as:
52 ;;
53 ;; (autoload 'ps-print-buffer "ps-print"
54 ;; "Generate and print a PostScript image of the buffer..." t)
55 ;;
56 ;; 3. Make sure that the variables ps-lpr-command and ps-lpr-switches
57 ;; contain appropriate values for your system; see the usage notes
58 ;; below and the documentation of these variables.
59 ;; 48 ;;
60 ;; Using ps-print 49 ;; Using ps-print
61 ;; -------------- 50 ;; --------------
62 ;; 51 ;;
63 ;; The Commands 52 ;; The Commands
172 ;; command and lpr-switches. 161 ;; command and lpr-switches.
173 ;; 162 ;;
174 ;; NOTE: ps-lpr-command and ps-lpr-switches take their initial values 163 ;; NOTE: ps-lpr-command and ps-lpr-switches take their initial values
175 ;; from the variables lpr-command and lpr-switches. If you have 164 ;; from the variables lpr-command and lpr-switches. If you have
176 ;; lpr-command set to invoke a pretty-printer such as enscript, 165 ;; lpr-command set to invoke a pretty-printer such as enscript,
177 ;; then ps-print won't work properly. Ps-lpr-command must name 166 ;; then ps-print won't work properly. ps-lpr-command must name
178 ;; a program that does not format the files it prints. 167 ;; a program that does not format the files it prints.
179 ;; 168 ;;
180 ;; 169 ;;
181 ;; How Ps-Print Deals With Fonts 170 ;; How Ps-Print Deals With Fonts
182 ;; 171 ;;
311 ;; 300 ;;
312 ;; The variable ps-paper-type determines the size of paper ps-print 301 ;; The variable ps-paper-type determines the size of paper ps-print
313 ;; formats for; it should contain one of the symbols ps-letter, 302 ;; formats for; it should contain one of the symbols ps-letter,
314 ;; ps-legal, or ps-a4. The default is ps-letter. 303 ;; ps-legal, or ps-a4. The default is ps-letter.
315 ;; 304 ;;
316 ;;
317 ;; New in version 1.6
318 ;; ------------------
319 ;; Color output capability.
320 ;;
321 ;; Automatic detection of font attributes (bold, italic).
322 ;;
323 ;; Configurable headers with page numbers.
324 ;;
325 ;; Slightly faster.
326 ;;
327 ;; Support for different paper sizes.
328 ;;
329 ;; Better conformance to PostScript Document Structure Conventions.
330 ;;
331 ;; 305 ;;
332 ;; Known bugs and limitations of ps-print: 306 ;; Known bugs and limitations of ps-print:
333 ;; -------------------------------------- 307 ;; --------------------------------------
308 ;; Automatic font-attribute detection doesn't work will, especially
309 ;; with hilit19 and older versions of get-create-face. Users having
310 ;; problems with auto-font detection should use the lists ps-italic-
311 ;; faces and ps-bold-faces and/or turn off automatic detection by
312 ;; setting ps-auto-font-detect to nil.
313 ;;
334 ;; Color output doesn't yet work in XEmacs. 314 ;; Color output doesn't yet work in XEmacs.
335 ;; 315 ;;
336 ;; Slow. Because XEmacs implements certain functions, such as 316 ;; Still too slow; could use some hand-optimization.
337 ;; next-property-change, in lisp, printing with faces is several times
338 ;; slower in XEmacs. In Emacs, these functions are implemented in C,
339 ;; so Emacs is somewhat faster.
340 ;; 317 ;;
341 ;; ASCII Control characters other than tab, linefeed and pagefeed are 318 ;; ASCII Control characters other than tab, linefeed and pagefeed are
342 ;; not handled. 319 ;; not handled.
343 ;; 320 ;;
344 ;; Default background color isn't working. 321 ;; Default background color isn't working.
382 ;; Jim 359 ;; Jim
383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
384 361
385 ;;; Code: 362 ;;; Code:
386 363
387 (defconst ps-print-version "1.10" 364 (defconst ps-print-thompson-version "1.14"
388 "ps-print.el,v 1.10 1995/01/09 14:45:03 jct Exp 365 "Report bugs to thompson@wg2.waii.com and bug-gnu-emacs@prep.ai.mit.edu.")
389
390 Please send all bug fixes and enhancements to
391 Jim Thompson <thompson@wg2.waii.com>.")
392 366
393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
394 ;; User Variables: 368 ;; User Variables:
395 369
396 (defvar ps-lpr-command lpr-command 370 (defvar ps-lpr-command lpr-command
408 will be reversed on duplex printers so that the page numbers fall to 382 will be reversed on duplex printers so that the page numbers fall to
409 the left on even-numbered pages.") 383 the left on even-numbered pages.")
410 384
411 (defvar ps-paper-type 'ps-letter 385 (defvar ps-paper-type 'ps-letter
412 "*Specifies the size of paper to format for. Should be one of 386 "*Specifies the size of paper to format for. Should be one of
413 'ps-letter, 'ps-legal, or 'ps-a4.") 387 `ps-letter', `ps-legal', or `ps-a4'.")
414 388
415 (defvar ps-print-header t 389 (defvar ps-print-header t
416 "*Non-nil means print a header at the top of each page. 390 "*Non-nil means print a header at the top of each page.
417 By default, the header displays the buffer name, page number, and, if 391 By default, the header displays the buffer name, page number, and, if
418 the buffer is visiting a file, the file's directory. Headers are 392 the buffer is visiting a file, the file's directory. Headers are
421 395
422 (defvar ps-print-header-frame t 396 (defvar ps-print-header-frame t
423 "*Non-nil means draw a gaudy frame around the header.") 397 "*Non-nil means draw a gaudy frame around the header.")
424 398
425 (defvar ps-show-n-of-n t 399 (defvar ps-show-n-of-n t
426 "*Non-nil means show page numbers as `N/M', meaning page N of M. 400 "*Non-nil means show page numbers as N/M, meaning page N of M.
427 Note: page numbers are displayed as part of headers, see variable `ps- 401 Note: page numbers are displayed as part of headers, see variable
428 print-headers'.") 402 `ps-print-headers'.")
429 403
430 (defvar ps-print-color-p (and (fboundp 'x-color-values) 404 (defvar ps-print-color-p (and (fboundp 'x-color-values)
431 (fboundp 'float)) 405 (fboundp 'float))
432 ; Printing color requires both floating point and x-color-values. 406 ; Printing color requires both floating point and x-color-values.
433 "*If non-nil, print the buffer's text in color.") 407 "*If non-nil, print the buffer's text in color.")
550 variable.") 524 variable.")
551 525
552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 526 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
553 ;; User commands 527 ;; User commands
554 528
529 ;;;###autoload
555 (defun ps-print-buffer (&optional filename) 530 (defun ps-print-buffer (&optional filename)
556 "Generate and print a PostScript image of the buffer. 531 "Generate and print a PostScript image of the buffer.
557 532
558 When called with a numeric prefix argument (C-u), prompts the user for 533 When called with a numeric prefix argument (C-u), prompts the user for
559 the name of a file to save the PostScript image in, instead of sending 534 the name of a file to save the PostScript image in, instead of sending
562 More specifically, the FILENAME argument is treated as follows: if it 537 More specifically, the FILENAME argument is treated as follows: if it
563 is nil, send the image to the printer. If FILENAME is a string, save 538 is nil, send the image to the printer. If FILENAME is a string, save
564 the PostScript image in a file with that name. If FILENAME is a 539 the PostScript image in a file with that name. If FILENAME is a
565 number, prompt the user for the name of the file to save in." 540 number, prompt the user for the name of the file to save in."
566 541
567 (interactive "P") 542 (interactive (list (ps-print-preprint current-prefix-arg)))
568 (setq filename (ps-print-preprint filename))
569 (ps-generate (current-buffer) (point-min) (point-max) 543 (ps-generate (current-buffer) (point-min) (point-max)
570 'ps-generate-postscript) 544 'ps-generate-postscript)
571 (ps-do-despool filename)) 545 (ps-do-despool filename))
572 546
573 547
548 ;;;###autoload
574 (defun ps-print-buffer-with-faces (&optional filename) 549 (defun ps-print-buffer-with-faces (&optional filename)
575 "Generate and print a PostScript image of the buffer. 550 "Generate and print a PostScript image of the buffer.
576 551
577 Like `ps-print-buffer', but includes font, color, and underline 552 Like `ps-print-buffer', but includes font, color, and underline
578 information in the generated image." 553 information in the generated image."
579 (interactive "P") 554 (interactive (list (ps-print-preprint current-prefix-arg)))
580 (setq filename (ps-print-preprint filename))
581 (ps-generate (current-buffer) (point-min) (point-max) 555 (ps-generate (current-buffer) (point-min) (point-max)
582 'ps-generate-postscript-with-faces) 556 'ps-generate-postscript-with-faces)
583 (ps-do-despool filename)) 557 (ps-do-despool filename))
584 558
585 559
560 ;;;###autoload
586 (defun ps-print-region (from to &optional filename) 561 (defun ps-print-region (from to &optional filename)
587 "Generate and print a PostScript image of the region. 562 "Generate and print a PostScript image of the region.
588 563
589 Like `ps-print-buffer', but prints just the current region." 564 Like `ps-print-buffer', but prints just the current region."
590 565
591 (interactive "r\nP") 566 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
592 (setq filename (ps-print-preprint filename))
593 (ps-generate (current-buffer) from to 567 (ps-generate (current-buffer) from to
594 'ps-generate-postscript) 568 'ps-generate-postscript)
595 (ps-do-despool filename)) 569 (ps-do-despool filename))
596 570
597 571
572 ;;;###autoload
598 (defun ps-print-region-with-faces (from to &optional filename) 573 (defun ps-print-region-with-faces (from to &optional filename)
599 "Generate and print a PostScript image of the region. 574 "Generate and print a PostScript image of the region.
600 575
601 Like `ps-print-region', but includes font, color, and underline 576 Like `ps-print-region', but includes font, color, and underline
602 information in the generated image." 577 information in the generated image."
603 578
604 (interactive "r\nP") 579 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
605 (setq filename (ps-print-preprint filename))
606 (ps-generate (current-buffer) from to 580 (ps-generate (current-buffer) from to
607 'ps-generate-postscript-with-faces) 581 'ps-generate-postscript-with-faces)
608 (ps-do-despool filename)) 582 (ps-do-despool filename))
609 583
610 584
585 ;;;###autoload
611 (defun ps-spool-buffer () 586 (defun ps-spool-buffer ()
612 "Generate and spool a PostScript image of the buffer. 587 "Generate and spool a PostScript image of the buffer.
613 588
614 Like `ps-print-buffer' except that the PostScript image is saved in a 589 Like `ps-print-buffer' except that the PostScript image is saved in a
615 local buffer to be sent to the printer later. 590 local buffer to be sent to the printer later.
618 (interactive) 593 (interactive)
619 (ps-generate (current-buffer) (point-min) (point-max) 594 (ps-generate (current-buffer) (point-min) (point-max)
620 'ps-generate-postscript)) 595 'ps-generate-postscript))
621 596
622 597
598 ;;;###autoload
623 (defun ps-spool-buffer-with-faces () 599 (defun ps-spool-buffer-with-faces ()
624 "Generate and spool a PostScript image of the buffer. 600 "Generate and spool a PostScript image of the buffer.
625 601
626 Like `ps-spool-buffer', but includes font, color, and underline 602 Like `ps-spool-buffer', but includes font, color, and underline
627 information in the generated image. 603 information in the generated image.
631 (interactive) 607 (interactive)
632 (ps-generate (current-buffer) (point-min) (point-max) 608 (ps-generate (current-buffer) (point-min) (point-max)
633 'ps-generate-postscript-with-faces)) 609 'ps-generate-postscript-with-faces))
634 610
635 611
612 ;;;###autoload
636 (defun ps-spool-region (from to) 613 (defun ps-spool-region (from to)
637 "Generate a PostScript image of the region and spool locally. 614 "Generate a PostScript image of the region and spool locally.
638 615
639 Like `ps-spool-buffer', but spools just the current region. 616 Like `ps-spool-buffer', but spools just the current region.
640 617
642 (interactive "r") 619 (interactive "r")
643 (ps-generate (current-buffer) from to 620 (ps-generate (current-buffer) from to
644 'ps-generate-postscript)) 621 'ps-generate-postscript))
645 622
646 623
624 ;;;###autoload
647 (defun ps-spool-region-with-faces (from to) 625 (defun ps-spool-region-with-faces (from to)
648 "Generate a PostScript image of the region and spool locally. 626 "Generate a PostScript image of the region and spool locally.
649 627
650 Like `ps-spool-region', but includes font, color, and underline 628 Like `ps-spool-region', but includes font, color, and underline
651 information in the generated image. 629 information in the generated image.
653 Use the command `ps-despool' to send the spooled images to the printer." 631 Use the command `ps-despool' to send the spooled images to the printer."
654 (interactive "r") 632 (interactive "r")
655 (ps-generate (current-buffer) from to 633 (ps-generate (current-buffer) from to
656 'ps-generate-postscript-with-faces)) 634 'ps-generate-postscript-with-faces))
657 635
636 ;;;###autoload
658 (defun ps-despool (&optional filename) 637 (defun ps-despool (&optional filename)
659 "Send the spooled PostScript to the printer. 638 "Send the spooled PostScript to the printer.
660 639
661 When called with a numeric prefix argument (C-u), prompt the user for 640 When called with a numeric prefix argument (C-u), prompt the user for
662 the name of a file to save the spooled PostScript in, instead of sending 641 the name of a file to save the spooled PostScript in, instead of sending
664 643
665 More specifically, the FILENAME argument is treated as follows: if it 644 More specifically, the FILENAME argument is treated as follows: if it
666 is nil, send the image to the printer. If FILENAME is a string, save 645 is nil, send the image to the printer. If FILENAME is a string, save
667 the PostScript image in a file with that name. If FILENAME is a 646 the PostScript image in a file with that name. If FILENAME is a
668 number, prompt the user for the name of the file to save in." 647 number, prompt the user for the name of the file to save in."
669 (interactive "P") 648 (interactive (list (ps-print-preprint current-prefix-arg)))
670 (ps-do-despool (ps-print-preprint filename))) 649 (ps-do-despool filename))
671 650
672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
673 ;; Utility functions and variables: 652 ;; Utility functions and variables:
674 653
675 (if (featurep 'emacs-vers) 654 (if (featurep 'emacs-vers)
805 784
806 /F { % Font select 785 /F { % Font select
807 findfont 786 findfont
808 dup /Ascent get /Ascent exch def 787 dup /Ascent get /Ascent exch def
809 dup /Descent get /Descent exch def 788 dup /Descent get /Descent exch def
810 dup /FontHeight get /LineHeight exch def 789 dup /FontHeight get /FontHeight exch def
811 dup /UnderlinePosition get /UnderlinePosition exch def 790 dup /UnderlinePosition get /UnderlinePosition exch def
812 dup /UnderlineThickness get /UnderlineThickness exch def 791 dup /UnderlineThickness get /UnderlineThickness exch def
813 setfont 792 setfont
814 } def 793 } def
815 794
928 /h0 14 /Helvetica-Bold Font 907 /h0 14 /Helvetica-Bold Font
929 /h1 12 /Helvetica Font 908 /h1 12 /Helvetica Font
930 909
931 /h1 F 910 /h1 F
932 911
933 /HeaderLineHeight LineHeight def 912 /HeaderLineHeight FontHeight def
934 /HeaderDescent Descent def 913 /HeaderDescent Descent def
935 /HeaderPad 2 def 914 /HeaderPad 2 def
936 915
937 /SetHeaderLines { 916 /SetHeaderLines {
938 /HeaderOffset TopMargin 2 div def 917 /HeaderOffset TopMargin 2 div def
1019 998
1020 /ReportFontInfo { 999 /ReportFontInfo {
1021 2 copy 1000 2 copy
1022 /t0 3 1 roll Font 1001 /t0 3 1 roll Font
1023 /t0 F 1002 /t0 F
1024 /lh LineHeight def 1003 /lh FontHeight def
1025 /sw ( ) stringwidth pop def 1004 /sw ( ) stringwidth pop def
1026 /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch 1005 /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch
1027 stringwidth pop exch div def 1006 stringwidth pop exch div def
1028 /t1 12 /Helvetica-Oblique Font 1007 /t1 12 /Helvetica-Oblique Font
1029 /t1 F 1008 /t1 F
1037 lh 32 string cvs show 1016 lh 32 string cvs show
1038 (, the space width is ) show 1017 (, the space width is ) show
1039 sw 32 string cvs show 1018 sw 32 string cvs show
1040 (,) show 1019 (,) show
1041 grestore 1020 grestore
1042 0 LineHeight neg rmoveto 1021 0 FontHeight neg rmoveto
1043 (and a crude estimate of average character width is ) show 1022 (and a crude estimate of average character width is ) show
1044 aw 32 string cvs show 1023 aw 32 string cvs show
1045 (.) show 1024 (.) show
1046 showpage 1025 showpage
1047 } def 1026 } def
1281 (ps-output (format "/TopMargin %d def\n" ps-top-margin)) 1260 (ps-output (format "/TopMargin %d def\n" ps-top-margin))
1282 1261
1283 (ps-get-page-dimensions) 1262 (ps-get-page-dimensions)
1284 (ps-output (format "/PrintWidth %d def\n" ps-print-width)) 1263 (ps-output (format "/PrintWidth %d def\n" ps-print-width))
1285 (ps-output (format "/PrintHeight %d def\n" ps-print-height)) 1264 (ps-output (format "/PrintHeight %d def\n" ps-print-height))
1265
1266 (ps-output (format "/LineHeight %d def\n" ps-line-height))
1286 1267
1287 (ps-output ps-print-prologue) 1268 (ps-output ps-print-prologue)
1288 1269
1289 (ps-output (format "/f0 %d /%s Font\n" ps-font-size ps-font)) 1270 (ps-output (format "/f0 %d /%s Font\n" ps-font-size ps-font))
1290 (ps-output (format "/f1 %d /%s Font\n" ps-font-size ps-font-bold)) 1271 (ps-output (format "/f1 %d /%s Font\n" ps-font-size ps-font-bold))
1423 (let* ((q-todo (- (point-max) (point-min))) 1404 (let* ((q-todo (- (point-max) (point-min)))
1424 (q-done (- (point) (point-min))) 1405 (q-done (- (point) (point-min)))
1425 (chunkfrac (/ q-todo 8)) 1406 (chunkfrac (/ q-todo 8))
1426 (chunksize (if (> chunkfrac 1000) 1000 chunkfrac))) 1407 (chunksize (if (> chunkfrac 1000) 1000 chunkfrac)))
1427 (if (> (- q-done ps-razchunk) chunksize) 1408 (if (> (- q-done ps-razchunk) chunksize)
1428 (progn 1409 (let (foo)
1429 (setq ps-razchunk q-done) 1410 (setq ps-razchunk q-done)
1430 (setq foo 1411 (setq foo
1431 (if (< q-todo 100) 1412 (if (< q-todo 100)
1432 (/ (* 100 q-done) q-todo) 1413 (/ (* 100 q-done) q-todo)
1433 (/ q-done (/ q-todo 100)))) 1414 (/ q-done (/ q-todo 100))))
1435 1416
1436 (defun ps-set-font (font) 1417 (defun ps-set-font (font)
1437 (setq ps-current-font font) 1418 (setq ps-current-font font)
1438 (ps-output (format "/f%d F\n" ps-current-font))) 1419 (ps-output (format "/f%d F\n" ps-current-font)))
1439 1420
1440 (defvar ps-print-color-scale (if ps-print-color-p 1421 (defvar ps-print-color-scale nil)
1441 (float (car (x-color-values "white")))
1442 1.0))
1443 1422
1444 (defun ps-set-bg (color) 1423 (defun ps-set-bg (color)
1445 (if (setq ps-current-bg color) 1424 (if (setq ps-current-bg color)
1446 (ps-output (format ps-color-format (nth 0 color) (nth 1 color) 1425 (ps-output (format ps-color-format (nth 0 color) (nth 1 color)
1447 (nth 2 color)) 1426 (nth 2 color))
1569 ps-bold-faces))) 1548 ps-bold-faces)))
1570 1549
1571 (defun ps-face-italic-p (face) 1550 (defun ps-face-italic-p (face)
1572 (if (eq emacs-type 'fsf) 1551 (if (eq emacs-type 'fsf)
1573 (ps-fsf-face-kind-p face 'italic "-[io]-" ps-italic-faces) 1552 (ps-fsf-face-kind-p face 'italic "-[io]-" ps-italic-faces)
1574 (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces))) 1553 (or
1554 (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces)
1555 (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces))))
1575 1556
1576 (defun ps-face-underlined-p (face) 1557 (defun ps-face-underlined-p (face)
1577 (or (face-underline-p face) 1558 (or (face-underline-p face)
1578 (memq face ps-underlined-faces))) 1559 (memq face ps-underlined-faces)))
1579 1560
1611 (list (extent-end-position extent) 'pull extent))) 1592 (list (extent-end-position extent) 'pull extent)))
1612 nil) 1593 nil)
1613 1594
1614 (defun ps-sorter (a b) 1595 (defun ps-sorter (a b)
1615 (< (car a) (car b))) 1596 (< (car a) (car b)))
1597
1598 (defun ps-extent-sorter (a b)
1599 (< (extent-priority a) (extent-priority b)))
1616 1600
1617 (defun ps-generate-postscript-with-faces (from to) 1601 (defun ps-generate-postscript-with-faces (from to)
1602 ;; Build the reference lists of faces if necessary.
1618 (if (or ps-always-build-face-reference 1603 (if (or ps-always-build-face-reference
1619 ps-build-face-reference) 1604 ps-build-face-reference)
1620 (progn 1605 (progn
1621 (message "Collecting face information...") 1606 (message "Collecting face information...")
1622 (ps-build-reference-face-lists))) 1607 (ps-build-reference-face-lists)))
1608 ;; Set the color scale. We do it here instead of in the defvar so
1609 ;; that ps-print can be dumped into emacs. This expression can't be
1610 ;; evaluated at dump-time because X isn't initialized.
1611 (setq ps-print-color-scale
1612 (if ps-print-color-p
1613 (float (car (x-color-values "white")))
1614 1.0))
1615 ;; Generate some PostScript.
1623 (save-restriction 1616 (save-restriction
1624 (narrow-to-region from to) 1617 (narrow-to-region from to)
1625 (let ((face 'default) 1618 (let ((face 'default)
1626 (position to)) 1619 (position to))
1627 (cond ((or (eq emacs-type 'lucid) (eq emacs-type 'xemacs)) 1620 (cond ((or (eq emacs-type 'lucid) (eq emacs-type 'xemacs))
1706 1699
1707 (defun ps-generate-postscript (from to) 1700 (defun ps-generate-postscript (from to)
1708 (ps-plot-region from to 0 nil)) 1701 (ps-plot-region from to 0 nil))
1709 1702
1710 (defun ps-generate (buffer from to genfunc) 1703 (defun ps-generate (buffer from to genfunc)
1711 (save-restriction 1704 (let ((from (min to from))
1712 (narrow-to-region from to) 1705 (to (max to from)))
1713 (if ps-razzle-dazzle 1706 (save-restriction
1714 (message "Formatting...%d%%" (setq ps-razchunk 0))) 1707 (narrow-to-region from to)
1715 (set-buffer buffer) 1708 (if ps-razzle-dazzle
1716 (setq ps-source-buffer buffer) 1709 (message "Formatting...%d%%" (setq ps-razchunk 0)))
1717 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name)) 1710 (set-buffer buffer)
1718 (ps-init-output-queue) 1711 (setq ps-source-buffer buffer)
1719 (let (safe-marker completed-safely needs-begin-file) 1712 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
1720 (unwind-protect 1713 (ps-init-output-queue)
1721 (progn 1714 (let (safe-marker completed-safely needs-begin-file)
1722 (set-buffer ps-spool-buffer) 1715 (unwind-protect
1723
1724 ;; Get a marker and make it point to the current end of the
1725 ;; buffer, If an error occurs, we'll delete everything from
1726 ;; the end of this marker onwards.
1727 (setq safe-marker (make-marker))
1728 (set-marker safe-marker (point-max))
1729
1730 (goto-char (point-min))
1731 (if (looking-at (regexp-quote "%!PS-Adobe-1.0"))
1732 nil
1733 (setq needs-begin-file t))
1734 (save-excursion
1735 (set-buffer ps-source-buffer)
1736 (if needs-begin-file (ps-begin-file))
1737 (ps-begin-job)
1738 (ps-begin-page))
1739 (set-buffer ps-source-buffer)
1740 (funcall genfunc from to)
1741 (ps-end-page)
1742
1743 (if (and ps-spool-duplex
1744 (= (mod ps-page-count 2) 1))
1745 (ps-dummy-page))
1746 (ps-flush-output)
1747
1748 ;; Back to the PS output buffer to set the page count
1749 (set-buffer ps-spool-buffer)
1750 (goto-char (point-max))
1751 (while (re-search-backward "^/PageCount 0 def$" nil t)
1752 (replace-match (format "/PageCount %d def" ps-page-count) t))
1753
1754 ;; Setting this variable tells the unwind form that the
1755 ;; the postscript was generated without error.
1756 (setq completed-safely t))
1757
1758 ;; Unwind form: If some bad mojo ocurred while generating
1759 ;; postscript, delete all the postscript that was generated.
1760 ;; This protects the previously spooled files from getting
1761 ;; corrupted.
1762 (if (and (markerp safe-marker) (not completed-safely))
1763 (progn 1716 (progn
1764 (set-buffer ps-spool-buffer) 1717 (set-buffer ps-spool-buffer)
1765 (delete-region (marker-position safe-marker) (point-max)))))) 1718
1766 1719 ;; Get a marker and make it point to the current end of the
1767 (if ps-razzle-dazzle 1720 ;; buffer, If an error occurs, we'll delete everything from
1768 (message "Formatting...done")))) 1721 ;; the end of this marker onwards.
1722 (setq safe-marker (make-marker))
1723 (set-marker safe-marker (point-max))
1724
1725 (goto-char (point-min))
1726 (if (looking-at (regexp-quote "%!PS-Adobe-1.0"))
1727 nil
1728 (setq needs-begin-file t))
1729 (save-excursion
1730 (set-buffer ps-source-buffer)
1731 (if needs-begin-file (ps-begin-file))
1732 (ps-begin-job)
1733 (ps-begin-page))
1734 (set-buffer ps-source-buffer)
1735 (funcall genfunc from to)
1736 (ps-end-page)
1737
1738 (if (and ps-spool-duplex
1739 (= (mod ps-page-count 2) 1))
1740 (ps-dummy-page))
1741 (ps-flush-output)
1742
1743 ;; Back to the PS output buffer to set the page count
1744 (set-buffer ps-spool-buffer)
1745 (goto-char (point-max))
1746 (while (re-search-backward "^/PageCount 0 def$" nil t)
1747 (replace-match (format "/PageCount %d def" ps-page-count) t))
1748
1749 ;; Setting this variable tells the unwind form that the
1750 ;; the postscript was generated without error.
1751 (setq completed-safely t))
1752
1753 ;; Unwind form: If some bad mojo ocurred while generating
1754 ;; postscript, delete all the postscript that was generated.
1755 ;; This protects the previously spooled files from getting
1756 ;; corrupted.
1757 (if (and (markerp safe-marker) (not completed-safely))
1758 (progn
1759 (set-buffer ps-spool-buffer)
1760 (delete-region (marker-position safe-marker) (point-max))))))
1761
1762 (if ps-razzle-dazzle
1763 (message "Formatting...done")))))
1769 1764
1770 (defun ps-do-despool (filename) 1765 (defun ps-do-despool (filename)
1771 (if (or (not (boundp 'ps-spool-buffer)) 1766 (if (or (not (boundp 'ps-spool-buffer))
1772 (not ps-spool-buffer)) 1767 (not ps-spool-buffer))
1773 (message "No spooled PostScript to print") 1768 (message "No spooled PostScript to print")
1816 1811
1817 ;; This stuff is for anybody that's brave enough to look this far, 1812 ;; This stuff is for anybody that's brave enough to look this far,
1818 ;; and able to figure out how to use it. It isn't really part of ps- 1813 ;; and able to figure out how to use it. It isn't really part of ps-
1819 ;; print, but I'll leave it here in hopes it might be useful: 1814 ;; print, but I'll leave it here in hopes it might be useful:
1820 1815
1816 (defmacro ps-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [f22] ''f22))
1817 (defmacro ps-c-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [C-f22]
1818 ''(control f22)))
1819 (defmacro ps-s-prsc () (list 'if (list 'eq 'emacs-type ''fsf) [S-f22]
1820 ''(shift f22)))
1821
1821 ;; Look in an article or mail message for the Subject: line. To be 1822 ;; Look in an article or mail message for the Subject: line. To be
1822 ;; placed in ps-left-headers. 1823 ;; placed in ps-left-headers.
1823 (defun ps-article-subject () 1824 (defun ps-article-subject ()
1824 (save-excursion 1825 (save-excursion
1825 (goto-char (point-min)) 1826 (goto-char (point-min))
1866 1867
1867 ;; A hook to bind to vm-mode-hook to locally bind prsc and set the ps- 1868 ;; A hook to bind to vm-mode-hook to locally bind prsc and set the ps-
1868 ;; left-headers specially for mail messages. This header setup would 1869 ;; left-headers specially for mail messages. This header setup would
1869 ;; also work, I think, for RMAIL. 1870 ;; also work, I think, for RMAIL.
1870 (defun ps-vm-mode-hook () 1871 (defun ps-vm-mode-hook ()
1871 (local-set-key 'f22 'ps-vm-print-message-from-summary) 1872 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
1872 (setq ps-header-lines 3) 1873 (setq ps-header-lines 3)
1873 (setq ps-left-header 1874 (setq ps-left-header
1874 ;; The left headers will display the message's subject, its 1875 ;; The left headers will display the message's subject, its
1875 ;; author, and the name of the folder it was in. 1876 ;; author, and the name of the folder it was in.
1876 (list 'ps-article-subject 'ps-article-author 'buffer-name))) 1877 (list 'ps-article-subject 'ps-article-author 'buffer-name)))
1897 (ps-spool-buffer-with-faces)))) 1898 (ps-spool-buffer-with-faces))))
1898 1899
1899 ;; A hook to bind to bind to gnus-summary-setup-buffer to locally bind 1900 ;; A hook to bind to bind to gnus-summary-setup-buffer to locally bind
1900 ;; prsc. 1901 ;; prsc.
1901 (defun ps-gnus-summary-setup () 1902 (defun ps-gnus-summary-setup ()
1902 (local-set-key 'f22 'ps-gnus-print-article-from-summary)) 1903 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
1903
1904 ;; File: lispref.info, Node: Standard Errors
1905 1904
1906 ;; Look in an article or mail message for the Subject: line. To be 1905 ;; Look in an article or mail message for the Subject: line. To be
1907 ;; placed in ps-left-headers. 1906 ;; placed in ps-left-headers.
1908 (defun ps-info-file () 1907 (defun ps-info-file ()
1909 (save-excursion 1908 (save-excursion
1925 (setq ps-left-header 1924 (setq ps-left-header
1926 ;; The left headers will display the node name and file name. 1925 ;; The left headers will display the node name and file name.
1927 (list 'ps-info-node 'ps-info-file))) 1926 (list 'ps-info-node 'ps-info-file)))
1928 1927
1929 (defun ps-jts-ps-setup () 1928 (defun ps-jts-ps-setup ()
1930 (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc 1929 (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
1931 (global-set-key '(shift f22) 'ps-spool-region-with-faces) 1930 (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
1932 (global-set-key '(control f22) 'ps-despool) 1931 (global-set-key (ps-c-prsc) 'ps-despool)
1933 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook) 1932 (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
1934 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup) 1933 (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
1935 (add-hook 'vm-mode-hook 'ps-vm-mode-hook) 1934 (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
1935 (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
1936 (add-hook 'Info-mode-hook 'ps-info-mode-hook) 1936 (add-hook 'Info-mode-hook 'ps-info-mode-hook)
1937 (setq ps-spool-duplex t) 1937 (setq ps-spool-duplex t)
1938 (setq ps-print-color-p nil) 1938 (setq ps-print-color-p nil)
1939 (setq ps-lpr-command "lpr") 1939 (setq ps-lpr-command "lpr")
1940 (setq ps-lpr-switches '("-Jjct,duplex_long"))) 1940 (setq ps-lpr-switches '("-Jjct,duplex_long")))