aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-08-20 23:11:35 +0000
committerRichard M. Stallman1997-08-20 23:11:35 +0000
commit87a16a065d3d52bfb34c62329ad57728b93a2a32 (patch)
treea7565ed73067aa07ed355daa0fa5f65aae1d4dce
parenta8a35e617a5acf8577a56c45ea9e8cc958c056a9 (diff)
downloademacs-87a16a065d3d52bfb34c62329ad57728b93a2a32.tar.gz
emacs-87a16a065d3d52bfb34c62329ad57728b93a2a32.zip
A lot of comment and doc fixes.
Replace: 'nil by nil, '() by nil, 't by t. (ps-print-version): New version number (3.05). (ps-zebra-stripe, ps-number-of-zebra, ps-line-number) (ps-print-background-image, ps-print-background-text): New variables to customize zebra stripes, line number, image background and text background features, respectively. (ps-adobe-tag): Tagged to PostScript level 3. (ps-print-buffer, ps-print-buffer-with-faces) (ps-print-region, ps-print-region-with-faces) (ps-spool-buffer, ps-spool-buffer-with-faces) (ps-spool-region, ps-spool-region-with-faces): Call more primitive functions for PostScript printing (functions below). (ps-print-with-faces, ps-print-without-faces) (ps-spool-with-faces, ps-spool-without-faces): More primitive functions for PostScript printing. (ps-line-lengths, ps-nb-pages-buffer, ps-nb-pages-region) (ps-line-lengths-internal, ps-nb-pages): Doc fixes. (ps-print-prologue-1): a lot of PostScript programming: /dobackgroundstring, /dounderline, /UL: Postscript functions deleted. /reencodeFontISO, /F, /BG, /HL, /W, /S, /BeginDSCPage, /BeginPage, /EndPage: adjusted for new effects (outline, shadow, etc). /PLN, /EF, /Hline, /doBox, /doRect, /doShadow, /doOutline, /FillBgColor, /doLineNumber, /printZebra, /doColumnZebra, /doZebra, /BeginBackImage, /EndBackImage, /ShowBackText: New procedures. (ps-current-underline-p, ps-set-underline): Var and fn deleted. (ps-showline-count, ps-background-pages, ps-background-all-pages) (ps-background-text-count, ps-background-image-count): New variables. (ps-header-font, ps-header-title-font) (ps-header-line-height, ps-header-title-line-height) (ps-landscape-page-height): Set initial value to nil. (ps-print-face-extension-alist, ps-print-face-map-alist): New variables for face remapping. (ps-new-faces, ps-extend-face-list, ps-extend-face): New functions for face remapping. (ps-override-list, ps-extension-to-bit-face) (ps-extension-to-screen-face, ps-extension-bit) (ps-initialize-faces, ps-map-font-lock, ps-screen-to-bit-face): New internal functions for face remapping. (ps-get-page-dimensions): Fix error message. (ps-insert-file): Doc fix and programming enhancement. (ps-begin-file, ps-end-file, ps-get-buffer-name, ps-begin-page) (ps-next-line, ps-plot-region, ps-face-attributes) (ps-face-attribute-list, ps-plot-with-face) (ps-generate-postscript-with-faces): Handle new output features. (ps-generate): save-excursion inserted to return back point at position before calling ps-print. (ps-do-spool): Access dos-ps-printer variable through symbol-value. (ps-prsc, ps-c-prsc, ps-s-prsc): Use backquote. (ps-basic-plot-whitespace, ps-emacs-face-kind-p): Internal blank line eliminated. (ps-float-format, ps-current-effect): New internal variables. (ps-output-list, ps-count-lines, ps-background-pages) (ps-get-boundingbox, ps-float-format, ps-background-text) (ps-background-image, ps-background, ps-header-height) (ps-get-face): New internal functions. (ps-control-character): Handle control characters. (ps-gnus-print-article-from-summary): Updated for Gnus 5. (ps-jack-setup): Replace 'nil by nil, 't by t.
-rw-r--r--lisp/ps-print.el1703
1 files changed, 1284 insertions, 419 deletions
diff --git a/lisp/ps-print.el b/lisp/ps-print.el
index 2ca7632a8e7..ffb430dbdf7 100644
--- a/lisp/ps-print.el
+++ b/lisp/ps-print.el
@@ -3,14 +3,14 @@
3;; Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. 3;; Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 4
5;; Author: Jim Thompson (was <thompson@wg2.waii.com>) 5;; Author: Jim Thompson (was <thompson@wg2.waii.com>)
6;; Author: Jacques Duthen <duthen@club-internet.fr> 6;; Author: Jacques Duthen <duthen@cegelec-red.fr>
7;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.br> 7;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.br>
8;; Keywords: print, PostScript 8;; Keywords: print, PostScript
9;; Time-stamp: <97/01/09 13:52:08 duthen> 9;; Time-stamp: <97/08/09 1:30:17 vinicius>
10;; Version: 3.04 10;; Version: 3.05
11 11
12(defconst ps-print-version "3.04" 12(defconst ps-print-version "3.05"
13 "ps-print.el, v 3.04 <97/01/09 duthen> 13 "ps-print.el, v 3.05 <97/08/09 vinicius>
14 14
15Jack's last change version -- this file may have been edited as part of 15Jack's last change version -- this file may have been edited as part of
16Emacs without changes to the version number. When reporting bugs, 16Emacs without changes to the version number. When reporting bugs,
@@ -18,7 +18,7 @@ please also report the version of Emacs, if any, that ps-print was
18distributed with. 18distributed with.
19 19
20Please send all bug fixes and enhancements to 20Please send all bug fixes and enhancements to
21 Jacques Duthen <duthen@club-internet.fr>>. 21 Jacques Duthen <duthen@cegelec-red.fr>.
22") 22")
23 23
24;; This file is part of GNU Emacs. 24;; This file is part of GNU Emacs.
@@ -51,6 +51,15 @@ Please send all bug fixes and enhancements to
51;; Emacs 19 or Lucid Emacs, together with a fontifying package such as 51;; Emacs 19 or Lucid Emacs, together with a fontifying package such as
52;; font-lock or hilit. 52;; font-lock or hilit.
53;; 53;;
54;; ps-print uses the same face attributes defined through font-lock or hilit
55;; to print a PostScript file, but some faces are better seeing on the screen
56;; than on paper, specially when you have a black/white PostScript printer.
57;;
58;; ps-print allows a remap of face to another one that it is better to print,
59;; for example, the face font-lock-comment-face (if you are using font-lock)
60;; could have bold or italic attribute when printing, besides foreground color.
61;; This remap improves printing look (see How Ps-Print Maps Faces).
62;;
54;; 63;;
55;; Using ps-print 64;; Using ps-print
56;; -------------- 65;; --------------
@@ -167,6 +176,7 @@ Please send all bug fixes and enhancements to
167;; command is used to send the PostScript images to the printer, and 176;; command is used to send the PostScript images to the printer, and
168;; what arguments to give the command. These are analogous to 177;; what arguments to give the command. These are analogous to
169;; `lpr-command' and `lpr-switches'. 178;; `lpr-command' and `lpr-switches'.
179;;
170;; Make sure that they contain appropriate values for your system; 180;; Make sure that they contain appropriate values for your system;
171;; see the usage notes below and the documentation of these variables. 181;; see the usage notes below and the documentation of these variables.
172;; 182;;
@@ -193,7 +203,7 @@ Please send all bug fixes and enhancements to
193;; of the printing on the page: 203;; of the printing on the page:
194;; nil means `portrait' mode, non-nil means `landscape' mode. 204;; nil means `portrait' mode, non-nil means `landscape' mode.
195;; There is no oblique mode yet, though this is easy to do in ps. 205;; There is no oblique mode yet, though this is easy to do in ps.
196 206;;
197;; In landscape mode, the text is NOT scaled: you may print 70 lines 207;; In landscape mode, the text is NOT scaled: you may print 70 lines
198;; in portrait mode and only 50 lignes in landscape mode. 208;; in portrait mode and only 50 lignes in landscape mode.
199;; The margins represent margins in the printed paper: 209;; The margins represent margins in the printed paper:
@@ -331,10 +341,13 @@ Please send all bug fixes and enhancements to
331;; 341;;
332;; Note that Curly has the PostScript string delimiters inside his 342;; Note that Curly has the PostScript string delimiters inside his
333;; quotes -- those aren't misplaced lisp delimiters! 343;; quotes -- those aren't misplaced lisp delimiters!
344;;
334;; Without them, PostScript would attempt to call the undefined 345;; Without them, PostScript would attempt to call the undefined
335;; function Curly, which would result in a PostScript error. 346;; function Curly, which would result in a PostScript error.
347;;
336;; Since most printers don't report PostScript errors except by 348;; Since most printers don't report PostScript errors except by
337;; aborting the print job, this kind of error can be hard to track down. 349;; aborting the print job, this kind of error can be hard to track down.
350;;
338;; Consider yourself warned! 351;; Consider yourself warned!
339;; 352;;
340;; 353;;
@@ -349,6 +362,37 @@ Please send all bug fixes and enhancements to
349;; for your printer. 362;; for your printer.
350;; 363;;
351;; 364;;
365;; Line Number
366;; -----------
367;;
368;; The variable `ps-line-number' determines if lines will be
369;; numerated (non-nil value) or not (nil value).
370;; The default is not numerated (nil value).
371;;
372;;
373;; Zebra Stripes
374;; -------------
375;;
376;; Zebra stripes is a kind of background effect, where the background looks
377;; like:
378;;
379;; XXXXXXXXXXXXXXXXXXXXXXXX
380;; XXXXXXXXXXXXXXXXXXXXXXXX
381;;
382;;
383;; XXXXXXXXXXXXXXXXXXXXXXXX
384;; XXXXXXXXXXXXXXXXXXXXXXXX
385;;
386;; The X's are representing a rectangle area filled with a light gray color.
387;;
388;; The variable `ps-zebra-stripe' determines if zebra stripe lines will be
389;; printed (non-nil value) or not (nil value).
390;; The default is not print zebra stripes (nil value).
391;;
392;; The variable `ps-number-of-zebra' indicates the number of lines on a
393;; zebra stripe. The default is 3.
394;;
395;;
352;; Font managing 396;; Font managing
353;; ------------- 397;; -------------
354;; 398;;
@@ -382,10 +426,10 @@ Please send all bug fixes and enhancements to
382;; ------------------------ 426;; ------------------------
383;; 427;;
384;; To use a new font family, you MUST first teach ps-print 428;; To use a new font family, you MUST first teach ps-print
385;; this font, ie add its information to `ps-font-info-database', 429;; this font, i.e., add its information to `ps-font-info-database',
386;; otherwise ps-print cannot correctly place line and page breaks. 430;; otherwise ps-print cannot correctly place line and page breaks.
387;; 431;;
388;; For example, assuming `Helvetica' is unkown, 432;; For example, assuming `Helvetica' is unknown,
389;; you first need to do the following ONLY ONCE: 433;; you first need to do the following ONLY ONCE:
390;; 434;;
391;; - create a new buffer 435;; - create a new buffer
@@ -484,6 +528,112 @@ Please send all bug fixes and enhancements to
484;; To turn off color output, set `ps-print-color-p' to nil. 528;; To turn off color output, set `ps-print-color-p' to nil.
485;; 529;;
486;; 530;;
531;; How Ps-Print Maps Faces
532;; -----------------------
533;;
534;; As ps-print uses PostScript to print buffers, it is possible to have
535;; other attributes associated with faces. So the new attributes used
536;; by ps-print are:
537;;
538;; strikeout - like underline, but the line is in middle of text.
539;; overline - like underline, but the line is over the text.
540;; shadow - text will have a shadow.
541;; box - text will be surrounded by a box.
542;; outline - only the text border font will be printed.
543;;
544;; See documentation for `ps-extend-face' and `ps-extend-face-list'.
545;;
546;; Besides remapping existing faces it is also possible to create new faces
547;; using `ps-new-faces' (see the documentation) for both the screen and
548;; printing presentation.
549;;
550;; Let's, for example, remap font-lock-keyword-face to another foreground color
551;; and bold attribute:
552;;
553;; (ps-extend-face '(font-lock-keyword-face "RoyalBlue" nil bold))
554;;
555;; If we wish to extend a list of faces, we could do:
556;;
557;; (ps-extend-face-list
558;; '((font-lock-function-name-face "Blue" nil bold)
559;; (font-lock-variable-name-face "Sienna" nil bold italic)
560;; (font-lock-keyword-face "RoyalBlue" nil underline))
561;; 'MERGE)
562;;
563;; And if we wish to create new faces and extend:
564;;
565;; (ps-new-faces
566;; ;; new faces for screen
567;; '((my-obsolete-face "White" "FireBrick" italic underline bold)
568;; (my-keyword-face "Blue")
569;; (my-comment-face "FireBrick" nil italic)
570;; (my-string-face "Grey40" nil italic))
571;; ;; face extension for printing
572;; '((my-keyword-face nil nil bold)
573;; (my-comment-face nil nil bold)
574;; (font-lock-function-name-face "Blue" nil bold)
575;; (font-lock-variable-name-face "Sienna" nil bold italic)
576;; (font-lock-keyword-face "RoyalBlue" nil underline))
577;; 'OVERRIDE 'MERGE)
578;;
579;; Note: the only attributes that have effect on screen are: bold, italic and
580;; underline. All other screen effect is ignored.
581;;
582;;
583;; How Ps-Print Has A Text And/Or Image On Background
584;; --------------------------------------------------
585;;
586;; Ps-print can print texts and/or EPS PostScript images on background; it is
587;; possible to define the following text attributes: font name, font size,
588;; initial position, angle, gray scale and pages to print.
589;;
590;; It has the following EPS PostScript images attributes: file name containing
591;; the image, initial position, X and Y scales, angle and pages to print.
592;;
593;; See documentation for `ps-print-background-text' and
594;; `ps-print-background-image'.
595;;
596;; For example, if we wish to print text "preliminary" on all pages and text
597;; "special" on page 5 and from page 11 to page 17, we could specify:
598;;
599;; (setq ps-print-background-text
600;; '(("preliminary")
601;; ("special"
602;; "LeftMargin" "BottomMargin PrintHeight add" ; X and Y position
603;; ; (upper left corner)
604;; nil nil nil
605;; "PrintHeight neg PrintWidth atan" ; angle
606;; 5 (11 . 17)) ; page list
607;; ))
608;;
609;; Similarly, we could print image "~/images/EPS-image1.ps" on all pages and
610;; image "~/images/EPS-image2.ps" on page 5 and from page 11 to page 17, we
611;; specify:
612;;
613;; (setq ps-print-background-image
614;; '(("~/images/EPS-image1.ps"
615;; "LeftMargin" "BottomMargin") ; X and Y position (lower left corner)
616;; ("~/images/EPS-image2.ps"
617;; "LeftMargin" "BottomMargin PrintHeight 2 div add" ; X and Y position
618;; ; (upper left corner)
619;; nil nil nil
620;; 5 (11 . 17)) ; page list
621;; ))
622;;
623;; If it is not possible to read (or does not exist) an image file, that file
624;; is ignored.
625;;
626;; The printing order is:
627;;
628;; 1. Print zebra stripes
629;; 2. Print background texts that it should be on all pages
630;; 3. Print background images that it should be on all pages
631;; 4. Print background texts only for current page (if any)
632;; 5. Print background images only for current page (if any)
633;; 6. Print header
634;; 7. Print buffer text (with faces, if specified) with line number
635;;
636;;
487;; Utilities 637;; Utilities
488;; --------- 638;; ---------
489;; 639;;
@@ -495,12 +645,12 @@ Please send all bug fixes and enhancements to
495;; left and right margins and the font size. On UN*X systems, do: 645;; left and right margins and the font size. On UN*X systems, do:
496;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head 646;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
497;; to determine the longest lines of your file. 647;; to determine the longest lines of your file.
498;; Then, the command `ps-line-lengths' will give you the correspondance 648;; Then, the command `ps-line-lengths' will give you the correspondence
499;; between a line length (number of characters) and the maximum font 649;; between a line length (number of characters) and the maximum font
500;; size which doesn't wrap such a line with the current ps-print setup. 650;; size which doesn't wrap such a line with the current ps-print setup.
501;; 651;;
502;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display 652;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
503;; the correspondance between a number of pages and the maximum font 653;; the correspondence between a number of pages and the maximum font
504;; size which allow the number of lines of the current buffer or of 654;; size which allow the number of lines of the current buffer or of
505;; its current region to fit in this number of pages. 655;; its current region to fit in this number of pages.
506;; Note: line folding is not taken into account in this process 656;; Note: line folding is not taken into account in this process
@@ -521,6 +671,15 @@ Please send all bug fixes and enhancements to
521;; New since version 2.8 671;; New since version 2.8
522;; --------------------- 672;; ---------------------
523;; 673;;
674;; [vinicius] 970809 Vinicius Jose Latorre <vinicius@cpqd.br>
675;;
676;; Handle control characters.
677;; Face remapping.
678;; New face attributes.
679;; Line number.
680;; Zebra stripes.
681;; Text and/or image on background.
682;;
524;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr> 683;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
525;; 684;;
526;; Font familiy and float size for text and header. 685;; Font familiy and float size for text and header.
@@ -550,9 +709,6 @@ Please send all bug fixes and enhancements to
550;; 709;;
551;; Still too slow; could use some hand-optimization. 710;; Still too slow; could use some hand-optimization.
552;; 711;;
553;; ASCII Control characters other than tab, linefeed and pagefeed are
554;; not handled.
555;;
556;; Default background color isn't working. 712;; Default background color isn't working.
557;; 713;;
558;; Faces are always treated as opaque. 714;; Faces are always treated as opaque.
@@ -718,20 +874,110 @@ see `ps-paper-type'."
718Should be one of the paper types defined in `ps-page-dimensions-database', for 874Should be one of the paper types defined in `ps-page-dimensions-database', for
719example `letter', `legal' or `a4'." 875example `letter', `legal' or `a4'."
720 :type '(symbol :validate (lambda (wid) 876 :type '(symbol :validate (lambda (wid)
721 (if (assq (widget-value wid) ps-page-dimensions-database) 877 (if (assq (widget-value wid)
878 ps-page-dimensions-database)
722 nil 879 nil
723 (widget-put wid :error "Unknown paper size") 880 (widget-put wid :error "Unknown paper size")
724 wid))) 881 wid)))
725 :group 'ps-print) 882 :group 'ps-print)
726 883
727(defcustom ps-landscape-mode 'nil 884(defcustom ps-landscape-mode nil
728 "*Non-nil means print in landscape mode." 885 "*Non-nil means print in landscape mode."
729 :type 'boolean 886 :type 'boolean
730 :group 'ps-print) 887 :group 'ps-print)
731 888
732(defcustom ps-number-of-columns (if ps-landscape-mode 2 1) 889(defcustom ps-number-of-columns (if ps-landscape-mode 2 1)
733 "*Specifies the number of columns" 890 "*Specifies the number of columns"
734 :type 'integer 891 :type 'number
892 :group 'ps-print)
893
894(defcustom ps-zebra-stripe nil
895 "*Non-nil means print zebra stripes.
896See also documentation for ps-print-n-zebra."
897 :type 'boolean
898 :group 'ps-print)
899
900(defcustom ps-number-of-zebra 3
901 "*Number of zebra stripe lines.
902See also documentation for ps-print-zebra."
903 :type 'number
904 :group 'ps-print)
905
906(defcustom ps-line-number nil
907 "*Non-nil means print line number."
908 :type 'boolean
909 :group 'ps-print)
910
911(defcustom ps-print-background-image nil
912 "*EPS image list to be printed on background.
913
914The elements are:
915
916 (FILENAME X Y XSCALE YSCALE ROTATION PAGES...)
917
918FILENAME is a file name which contains an EPS image or some PostScript
919programming like EPS.
920FILENAME is ignored, if it doesn't exist or is read protected.
921
922X and Y are relative positions on paper to put the image.
923If X and Y are nil, the image is centralized on paper.
924
925XSCALE and YSCALE are scale factor to be applied to image before printing.
926If XSCALE and YSCALE are nil, the original size is used.
927
928ROTATION is the image rotation angle; if nil, the default is 0.
929
930PAGES designates the page to print background image.
931PAGES may be a number or a cons cell (FROM . TO) designating FROM page
932to TO page.
933If PAGES is nil, print background image on all pages.
934
935X, Y, XSCALE, YSCALE and ROTATION may be a floating point number,
936an integer number or a string. If it is a string, the string should contain
937PostScript programming that returns a float or integer value.
938
939For example, if you wish to print an EPS image on all pages do:
940
941 '((\"~/images/EPS-image.ps\"))"
942 :type 'list
943 :group 'ps-print)
944
945(defcustom ps-print-background-text nil
946 "*Text list to be printed on background.
947
948The elements are:
949
950 (STRING X Y FONT FONTSIZE GRAY ROTATION PAGES...)
951
952STRING is the text to be printed on background.
953
954X and Y are positions on paper to put the text.
955If X and Y are nil, the text is positioned at lower left corner.
956
957FONT is a font name to be used on printing the text.
958If nil, \"Times-Roman\" is used.
959
960FONTSIZE is font size to be used, if nil, 200 is used.
961
962GRAY is the text gray factor (should be very light like 0.8).
963If nil, the default is 0.85.
964
965ROTATION is the text rotation angle; if nil, the angle is given by
966the diagonal from lower left corner to upper right corner.
967
968PAGES designates the page to print background text.
969PAGES may be a number or a cons cell (FROM . TO) designating FROM page
970to TO page.
971If PAGES is nil, print background text on all pages.
972
973X, Y, FONTSIZE, GRAY and ROTATION may be a floating point number,
974an integer number or a string. If it is a string, the string should contain
975PostScript programming that returns a float or integer value.
976
977For example, if you wish to print text \"Preliminary\" on all pages do:
978
979 '((\"Preliminary\"))"
980 :type 'list
735 :group 'ps-print) 981 :group 'ps-print)
736 982
737;;; Horizontal layout 983;;; Horizontal layout
@@ -883,7 +1129,7 @@ the left on even-numbered pages."
883 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic" 1129 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
884 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic" 1130 "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
885 10.0 11.45 2.2 4.10811) 1131 10.0 11.45 2.2 4.10811)
886) 1132 )
887 "*Font info database: font family (the key), name, bold, italic, bold-italic, 1133 "*Font info database: font family (the key), name, bold, italic, bold-italic,
888reference size, line height, space width, average character width. 1134reference size, line height, space width, average character width.
889To get the info for another specific font (say Helvetica), do the following: 1135To get the info for another specific font (say Helvetica), do the following:
@@ -891,9 +1137,9 @@ To get the info for another specific font (say Helvetica), do the following:
891- generate the PostScript image to a file (C-u M-x ps-print-buffer) 1137- generate the PostScript image to a file (C-u M-x ps-print-buffer)
892- open this file and delete the leading `%' (which is the Postscript 1138- open this file and delete the leading `%' (which is the Postscript
893 comment character) from the line 1139 comment character) from the line
894 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage' 1140 `% 3 cm 20 cm moveto 10 /Courier ReportFontInfo showpage'
895 to get the line 1141 to get the line
896 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage' 1142 `3 cm 20 cm moveto 10 /Helvetica ReportFontInfo showpage'
897- add the values to `ps-font-info-database'. 1143- add the values to `ps-font-info-database'.
898You can get all the fonts of YOUR printer using `ReportAllFontInfo'." 1144You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
899 :type '(repeat (list :tag "Font Definition" 1145 :type '(repeat (list :tag "Font Definition"
@@ -936,10 +1182,9 @@ when generating Postscript."
936 1182
937;;; Colors 1183;;; Colors
938 1184
939(defcustom ps-print-color-p (or (fboundp 'x-color-values) ; Emacs 1185;; Printing color requires x-color-values.
1186(defcustom ps-print-color-p (or (fboundp 'x-color-values) ; Emacs
940 (fboundp 'pixel-components)) ; XEmacs 1187 (fboundp 'pixel-components)) ; XEmacs
941 ; xemacs
942; Printing color requires x-color-values.
943 "*If non-nil, print the buffer's text in color." 1188 "*If non-nil, print the buffer's text in color."
944 :type 'boolean 1189 :type 'boolean
945 :group 'ps-print-color) 1190 :group 'ps-print-color)
@@ -1032,7 +1277,7 @@ this variable."
1032 :type 'boolean 1277 :type 'boolean
1033 :group 'ps-print) 1278 :group 'ps-print)
1034 1279
1035(defvar ps-adobe-tag "%!PS-Adobe-1.0\n" 1280(defvar ps-adobe-tag "%!PS-Adobe-3.0\n"
1036 "*Contains the header line identifying the output as PostScript. 1281 "*Contains the header line identifying the output as PostScript.
1037By default, `ps-adobe-tag' contains the standard identifier. Some 1282By default, `ps-adobe-tag' contains the standard identifier. Some
1038printers require slightly different versions of this line.") 1283printers require slightly different versions of this line.")
@@ -1076,11 +1321,8 @@ More specifically, the FILENAME argument is treated as follows: if it
1076is nil, send the image to the printer. If FILENAME is a string, save 1321is nil, send the image to the printer. If FILENAME is a string, save
1077the PostScript image in a file with that name. If FILENAME is a 1322the PostScript image in a file with that name. If FILENAME is a
1078number, prompt the user for the name of the file to save in." 1323number, prompt the user for the name of the file to save in."
1079
1080 (interactive (list (ps-print-preprint current-prefix-arg))) 1324 (interactive (list (ps-print-preprint current-prefix-arg)))
1081 (ps-generate (current-buffer) (point-min) (point-max) 1325 (ps-print-without-faces (point-min) (point-max) filename))
1082 'ps-generate-postscript)
1083 (ps-do-despool filename))
1084 1326
1085 1327
1086;;;###autoload 1328;;;###autoload
@@ -1090,20 +1332,15 @@ Like `ps-print-buffer', but includes font, color, and underline
1090information in the generated image. This command works only if you 1332information in the generated image. This command works only if you
1091are using a window system, so it has a way to determine color values." 1333are using a window system, so it has a way to determine color values."
1092 (interactive (list (ps-print-preprint current-prefix-arg))) 1334 (interactive (list (ps-print-preprint current-prefix-arg)))
1093 (ps-generate (current-buffer) (point-min) (point-max) 1335 (ps-print-with-faces (point-min) (point-max) filename))
1094 'ps-generate-postscript-with-faces)
1095 (ps-do-despool filename))
1096 1336
1097 1337
1098;;;###autoload 1338;;;###autoload
1099(defun ps-print-region (from to &optional filename) 1339(defun ps-print-region (from to &optional filename)
1100 "Generate and print a PostScript image of the region. 1340 "Generate and print a PostScript image of the region.
1101Like `ps-print-buffer', but prints just the current region." 1341Like `ps-print-buffer', but prints just the current region."
1102
1103 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg))) 1342 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
1104 (ps-generate (current-buffer) from to 1343 (ps-print-without-faces from to filename))
1105 'ps-generate-postscript)
1106 (ps-do-despool filename))
1107 1344
1108 1345
1109;;;###autoload 1346;;;###autoload
@@ -1112,11 +1349,10 @@ Like `ps-print-buffer', but prints just the current region."
1112Like `ps-print-region', but includes font, color, and underline 1349Like `ps-print-region', but includes font, color, and underline
1113information in the generated image. This command works only if you 1350information in the generated image. This command works only if you
1114are using a window system, so it has a way to determine color values." 1351are using a window system, so it has a way to determine color values."
1115
1116 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg))) 1352 (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
1117 (ps-generate (current-buffer) from to 1353 (ps-generate (current-buffer) from to
1118 'ps-generate-postscript-with-faces) 1354 'ps-generate-postscript-with-faces)
1119 (ps-do-despool filename)) 1355 (ps-print-with-faces from to filename))
1120 1356
1121 1357
1122;;;###autoload 1358;;;###autoload
@@ -1127,8 +1363,7 @@ local buffer to be sent to the printer later.
1127 1363
1128Use the command `ps-despool' to send the spooled images to the printer." 1364Use the command `ps-despool' to send the spooled images to the printer."
1129 (interactive) 1365 (interactive)
1130 (ps-generate (current-buffer) (point-min) (point-max) 1366 (ps-spool-without-faces (point-min) (point-max)))
1131 'ps-generate-postscript))
1132 1367
1133 1368
1134;;;###autoload 1369;;;###autoload
@@ -1139,10 +1374,8 @@ information in the generated image. This command works only if you
1139are using a window system, so it has a way to determine color values. 1374are using a window system, so it has a way to determine color values.
1140 1375
1141Use the command `ps-despool' to send the spooled images to the printer." 1376Use the command `ps-despool' to send the spooled images to the printer."
1142
1143 (interactive) 1377 (interactive)
1144 (ps-generate (current-buffer) (point-min) (point-max) 1378 (ps-spool-with-faces (point-min) (point-max)))
1145 'ps-generate-postscript-with-faces))
1146 1379
1147 1380
1148;;;###autoload 1381;;;###autoload
@@ -1152,8 +1385,7 @@ Like `ps-spool-buffer', but spools just the current region.
1152 1385
1153Use the command `ps-despool' to send the spooled images to the printer." 1386Use the command `ps-despool' to send the spooled images to the printer."
1154 (interactive "r") 1387 (interactive "r")
1155 (ps-generate (current-buffer) from to 1388 (ps-spool-without-faces from to))
1156 'ps-generate-postscript))
1157 1389
1158 1390
1159;;;###autoload 1391;;;###autoload
@@ -1165,8 +1397,7 @@ are using a window system, so it has a way to determine color values.
1165 1397
1166Use the command `ps-despool' to send the spooled images to the printer." 1398Use the command `ps-despool' to send the spooled images to the printer."
1167 (interactive "r") 1399 (interactive "r")
1168 (ps-generate (current-buffer) from to 1400 (ps-spool-with-faces from to))
1169 'ps-generate-postscript-with-faces))
1170 1401
1171;;;###autoload 1402;;;###autoload
1172(defun ps-despool (&optional filename) 1403(defun ps-despool (&optional filename)
@@ -1185,7 +1416,7 @@ number, prompt the user for the name of the file to save in."
1185 1416
1186;;;###autoload 1417;;;###autoload
1187(defun ps-line-lengths () 1418(defun ps-line-lengths ()
1188 "*Display the correspondance between a line length and a font size, 1419 "*Display the correspondence between a line length and a font size,
1189using the current ps-print setup. 1420using the current ps-print setup.
1190Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head" 1421Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1191 (interactive) 1422 (interactive)
@@ -1193,7 +1424,7 @@ Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1193 1424
1194;;;###autoload 1425;;;###autoload
1195(defun ps-nb-pages-buffer (nb-lines) 1426(defun ps-nb-pages-buffer (nb-lines)
1196 "*Display an approximate correspondance between a font size and the number 1427 "*Display an approximate correspondence between a font size and the number
1197of pages the current buffer would require to print 1428of pages the current buffer would require to print
1198using the current ps-print setup." 1429using the current ps-print setup."
1199 (interactive (list (count-lines (point-min) (point-max)))) 1430 (interactive (list (count-lines (point-min) (point-max))))
@@ -1201,7 +1432,7 @@ using the current ps-print setup."
1201 1432
1202;;;###autoload 1433;;;###autoload
1203(defun ps-nb-pages-region (nb-lines) 1434(defun ps-nb-pages-region (nb-lines)
1204 "*Display an approximate correspondance between a font size and the number 1435 "*Display an approximate correspondence between a font size and the number
1205of pages the current region would require to print 1436of pages the current region would require to print
1206using the current ps-print setup." 1437using the current ps-print setup."
1207 (interactive (list (count-lines (mark) (point)))) 1438 (interactive (list (count-lines (mark) (point))))
@@ -1359,7 +1590,7 @@ StandardEncoding 46 82 getinterval aload pop
1359 1590
1360/reencodeFontISO { %def 1591/reencodeFontISO { %def
1361 dup 1592 dup
1362 length 5 add dict % Make a new font (a new dict the same size 1593 length 12 add dict % Make a new font (a new dict the same size
1363 % as the old one) with room for our new symbols. 1594 % as the old one) with room for our new symbols.
1364 1595
1365 begin % Make the new font the current dictionary. 1596 begin % Make the new font the current dictionary.
@@ -1395,27 +1626,16 @@ StandardEncoding 46 82 getinterval aload pop
1395 /FontHeight Ascent Descent sub def % use `sub' because descent < 0 1626 /FontHeight Ascent Descent sub def % use `sub' because descent < 0
1396 1627
1397 % Define these in case they're not in the FontInfo 1628 % Define these in case they're not in the FontInfo
1398 % (also, here they're easier to get to. 1629 % (also, here they're easier to get to).
1399 /UnderlinePosition 1 def 1630 /UnderlinePosition Descent 0.70 mul def
1400 /UnderlineThickness 1 def 1631 /OverlinePosition Descent UnderlinePosition sub Ascent add def
1401 1632 /StrikeoutPosition Ascent 0.30 mul def
1402 % Get the underline position and thickness if they're defined. 1633 /LineThickness 0 50 FontMatrix transform exch pop def
1403 currentdict /FontInfo known { 1634 /Xshadow 0 80 FontMatrix transform exch pop def
1404 FontInfo 1635 /Yshadow 0 -90 FontMatrix transform exch pop def
1405 1636 /SpaceBackground Descent neg UnderlinePosition add def
1406 dup /UnderlinePosition known { 1637 /XBox Descent neg def
1407 dup /UnderlinePosition get 1638 /YBox LineThickness 0.7 mul def
1408 0 exch FontMatrix transform exch pop
1409 /UnderlinePosition exch def
1410 } if
1411
1412 dup /UnderlineThickness known {
1413 /UnderlineThickness get
1414 0 exch FontMatrix transform exch pop
1415 /UnderlineThickness exch def
1416 } if
1417
1418 } if
1419 1639
1420 currentdict % Leave the new font on the stack 1640 currentdict % Leave the new font on the stack
1421 end % Stop using the font as the current dictionary. 1641 end % Stop using the font as the current dictionary.
@@ -1429,11 +1649,18 @@ StandardEncoding 46 82 getinterval aload pop
1429 1649
1430/F { % Font selection 1650/F { % Font selection
1431 findfont 1651 findfont
1432 dup /Ascent get /Ascent exch def 1652 dup /Ascent get /Ascent exch def
1433 dup /Descent get /Descent exch def 1653 dup /Descent get /Descent exch def
1434 dup /FontHeight get /FontHeight exch def 1654 dup /FontHeight get /FontHeight exch def
1435 dup /UnderlinePosition get /UnderlinePosition exch def 1655 dup /UnderlinePosition get /UnderlinePosition exch def
1436 dup /UnderlineThickness get /UnderlineThickness exch def 1656 dup /OverlinePosition get /OverlinePosition exch def
1657 dup /StrikeoutPosition get /StrikeoutPosition exch def
1658 dup /LineThickness get /LineThickness exch def
1659 dup /Xshadow get /Xshadow exch def
1660 dup /Yshadow get /Yshadow exch def
1661 dup /SpaceBackground get /SpaceBackground exch def
1662 dup /XBox get /XBox exch def
1663 dup /YBox get /YBox exch def
1437 setfont 1664 setfont
1438} def 1665} def
1439 1666
@@ -1442,7 +1669,10 @@ StandardEncoding 46 82 getinterval aload pop
1442/bg false def 1669/bg false def
1443/BG { 1670/BG {
1444 dup /bg exch def 1671 dup /bg exch def
1445 { mark 4 1 roll ] /bgcolor exch def } if 1672 {mark 4 1 roll ]}
1673 {[ 1.0 1.0 1.0 ]}
1674 ifelse
1675 /bgcolor exch def
1446} def 1676} def
1447 1677
1448% B width C 1678% B width C
@@ -1468,22 +1698,6 @@ StandardEncoding 46 82 getinterval aload pop
1468 grestore 1698 grestore
1469} def 1699} def
1470 1700
1471/dobackgroundstring { % string --
1472 stringwidth pop
1473 dobackground
1474} def
1475
1476/dounderline { % fromx fromy --
1477 currentpoint
1478 gsave
1479 UnderlineThickness setlinewidth
1480 4 2 roll
1481 UnderlinePosition add moveto
1482 UnderlinePosition add lineto
1483 stroke
1484 grestore
1485} def
1486
1487/eolbg { % dobackground until right margin 1701/eolbg { % dobackground until right margin
1488 PrintWidth % -- x-eol 1702 PrintWidth % -- x-eol
1489 currentpoint pop % -- cur-x 1703 currentpoint pop % -- cur-x
@@ -1491,43 +1705,211 @@ StandardEncoding 46 82 getinterval aload pop
1491 dobackground 1705 dobackground
1492} def 1706} def
1493 1707
1494/eolul { % idem for underline 1708/PLN {PrintLineNumber {doLineNumber}if} def
1495 PrintWidth % -- x-eol
1496 currentpoint exch pop % -- x-eol cur-y
1497 dounderline
1498} def
1499 1709
1500/SL { % Soft Linefeed 1710/SL { % Soft Linefeed
1501 bg { eolbg } if 1711 bg { eolbg } if
1502 ul { eolul } if
1503 0 currentpoint exch pop LineHeight sub moveto 1712 0 currentpoint exch pop LineHeight sub moveto
1504} def 1713} def
1505 1714
1506/HL /SL load def % Hard Linefeed 1715/HL {SL PLN} def % Hard Linefeed
1507
1508/sp1 { currentpoint 3 -1 roll } def
1509 1716
1510% Some debug 1717% Some debug
1511/dcp { currentpoint exch 40 string cvs print (, ) print = } def 1718/dcp { currentpoint exch 40 string cvs print (, ) print = } def
1512/dp { print 2 copy 1719/dp { print 2 copy exch 40 string cvs print (, ) print = } def
1513 exch 40 string cvs print (, ) print = } def
1514
1515/S {
1516 bg { dup dobackgroundstring } if
1517 ul { sp1 } if
1518 show
1519 ul { dounderline } if
1520} def
1521 1720
1522/W { 1721/W {
1523 ul { sp1 } if
1524 ( ) stringwidth % Get the width of a space in the current font. 1722 ( ) stringwidth % Get the width of a space in the current font.
1525 pop % Discard the Y component. 1723 pop % Discard the Y component.
1526 mul % Multiply the width of a space 1724 mul % Multiply the width of a space
1527 % by the number of spaces to plot 1725 % by the number of spaces to plot
1528 bg { dup dobackground } if 1726 bg { dup dobackground } if
1529 0 rmoveto 1727 0 rmoveto
1530 ul { dounderline } if 1728} def
1729
1730/Effect 0 def
1731/EF {/Effect exch def} def
1732
1733% stack: string |- --
1734% effect: 1 - underline 2 - strikeout 4 - overline
1735% 8 - shadow 16 - box 32 - outline
1736/S {
1737 /xx currentpoint dup Descent add /yy exch def
1738 Ascent add /YY exch def def
1739 dup stringwidth pop xx add /XX exch def
1740 Effect 8 and 0 ne {
1741 /yy yy Yshadow add def
1742 /XX XX Xshadow add def
1743 } if
1744 bg {
1745 true
1746 Effect 16 and 0 ne
1747 {SpaceBackground doBox}
1748 {xx yy XX YY doRect}
1749 ifelse
1750 } if % background
1751 Effect 16 and 0 ne {false 0 doBox}if % box
1752 Effect 8 and 0 ne {dup doShadow}if % shadow
1753 Effect 32 and 0 ne
1754 {true doOutline} % outline
1755 {show} % normal text
1756 ifelse
1757 Effect 1 and 0 ne {UnderlinePosition Hline}if % underline
1758 Effect 2 and 0 ne {StrikeoutPosition Hline}if % strikeout
1759 Effect 4 and 0 ne {OverlinePosition Hline}if % overline
1760} bind def
1761
1762% stack: position |- --
1763/Hline {
1764 currentpoint exch pop add dup
1765 gsave
1766 newpath
1767 xx exch moveto
1768 XX exch lineto
1769 closepath
1770 LineThickness setlinewidth stroke
1771 grestore
1772} bind def
1773
1774% stack: fill-or-not delta |- --
1775/doBox {
1776 /dd exch def
1777 xx XBox sub dd sub yy YBox sub dd sub
1778 XX XBox add dd add YY YBox add dd add
1779 doRect
1780} bind def
1781
1782% stack: fill-or-not lower-x lower-y upper-x upper-y |- --
1783/doRect {
1784 /rYY exch def
1785 /rXX exch def
1786 /ryy exch def
1787 /rxx exch def
1788 gsave
1789 newpath
1790 rXX rYY moveto
1791 rxx rYY lineto
1792 rxx ryy lineto
1793 rXX ryy lineto
1794 closepath
1795 % top of stack: fill-or-not
1796 {FillBgColor}
1797 {LineThickness setlinewidth stroke}
1798 ifelse
1799 grestore
1800} bind def
1801
1802% stack: string |- --
1803/doShadow {
1804 gsave
1805 Xshadow Yshadow rmoveto
1806 false doOutline
1807 grestore
1808} bind def
1809
1810/st 1 string def
1811
1812% stack: string fill-or-not |- --
1813/doOutline {
1814 /-fillp- exch def
1815 /-ox- currentpoint /-oy- exch def def
1816 gsave
1817 LineThickness setlinewidth
1818 {
1819 st 0 3 -1 roll put
1820 st dup true charpath
1821 -fillp- {gsave FillBgColor grestore}if
1822 stroke stringwidth
1823 -oy- add /-oy- exch def
1824 -ox- add /-ox- exch def
1825 -ox- -oy- moveto
1826 } forall
1827 grestore
1828 -ox- -oy- moveto
1829} bind def
1830
1831% stack: --
1832/FillBgColor {bgcolor aload pop setrgbcolor fill} bind def
1833
1834/L0 6 /Times-Italic DefFont
1835
1836% stack: --
1837/doLineNumber {
1838 currentfont
1839 gsave
1840 0.0 0.0 0.0 setrgbcolor
1841 /L0 findfont setfont
1842 LineNumber Lines ge
1843 {(end )}
1844 {LineNumber 6 string cvs ( ) strcat}
1845 ifelse
1846 dup stringwidth pop neg 0 rmoveto
1847 show
1848 grestore
1849 setfont
1850 /LineNumber LineNumber 1 add def
1851} def
1852
1853% stack: --
1854/printZebra {
1855 gsave
1856 0.985 setgray
1857 /double-zebra NumberOfZebra NumberOfZebra add def
1858 /yiter double-zebra LineHeight mul neg def
1859 /xiter PrintWidth InterColumn add def
1860 NumberOfColumns {LinesPerColumn doColumnZebra xiter 0 rmoveto}repeat
1861 grestore
1862} def
1863
1864% stack: lines-per-column |- --
1865/doColumnZebra {
1866 gsave
1867 dup double-zebra idiv {NumberOfZebra doZebra 0 yiter rmoveto}repeat
1868 double-zebra mod
1869 dup 0 le {pop}{dup NumberOfZebra gt {pop NumberOfZebra}if doZebra}ifelse
1870 grestore
1871} def
1872
1873% stack: zebra-height (in lines) |- --
1874/doZebra {
1875 /zh exch 0.05 sub LineHeight mul def
1876 gsave
1877 0 LineHeight 0.65 mul rmoveto
1878 PrintWidth 0 rlineto
1879 0 zh neg rlineto
1880 PrintWidth neg 0 rlineto
1881 0 zh rlineto
1882 fill
1883 grestore
1884} def
1885
1886% tx ty rotation xscale yscale xpos ypos BeginBackImage
1887/BeginBackImage {
1888 /-save-image- save def
1889 /showpage {}def
1890 translate
1891 scale
1892 rotate
1893 translate
1894} def
1895
1896/EndBackImage {
1897 -save-image- restore
1898} def
1899
1900% string fontsize fontname rotation gray xpos ypos ShowBackText
1901/ShowBackText {
1902 gsave
1903 translate
1904 setgray
1905 rotate
1906 findfont exch dup /-offset- exch -0.25 mul def scalefont setfont
1907 0 -offset- moveto
1908 /-saveLineThickness- LineThickness def
1909 /LineThickness 1 def
1910 false doOutline
1911 /LineThickness -saveLineThickness- def
1912 grestore
1531} def 1913} def
1532 1914
1533/BeginDoc { 1915/BeginDoc {
@@ -1560,7 +1942,12 @@ StandardEncoding 46 82 getinterval aload pop
1560 1942
1561/BeginDSCPage { 1943/BeginDSCPage {
1562 % ---- when 1st column, save the state of the page 1944 % ---- when 1st column, save the state of the page
1563 ColumnIndex 1 eq { /pageState save def } if 1945 ColumnIndex 1 eq { /pageState save def
1946 0 PrintStartY moveto % move to where printing will start
1947 Zebra {printZebra}if
1948 printGlobalBackground
1949 printLocalBackground
1950 } if
1564 % ---- save the state of the column 1951 % ---- save the state of the column
1565 /columnState save def 1952 /columnState save def
1566} def 1953} def
@@ -1571,11 +1958,11 @@ StandardEncoding 46 82 getinterval aload pop
1571 HeaderText 1958 HeaderText
1572 } if 1959 } if
1573 0 PrintStartY moveto % move to where printing will start 1960 0 PrintStartY moveto % move to where printing will start
1961 PLN
1574} def 1962} def
1575 1963
1576/EndPage { 1964/EndPage {
1577 bg { eolbg } if 1965 bg { eolbg } if
1578 ul { eolul } if
1579} def 1966} def
1580 1967
1581/EndDSCPage { 1968/EndDSCPage {
@@ -1594,10 +1981,6 @@ StandardEncoding 46 82 getinterval aload pop
1594 } ifelse 1981 } ifelse
1595} def 1982} def
1596 1983
1597/ul false def
1598
1599/UL { /ul exch def } def
1600
1601/SetHeaderLines { % nb-lines -- 1984/SetHeaderLines { % nb-lines --
1602 /HeaderLines exch def 1985 /HeaderLines exch def
1603 % ---- bottom up 1986 % ---- bottom up
@@ -1777,9 +2160,14 @@ StandardEncoding 46 82 getinterval aload pop
1777 2160
1778(defvar ps-page-count 0) 2161(defvar ps-page-count 0)
1779(defvar ps-showpage-count 0) 2162(defvar ps-showpage-count 0)
2163(defvar ps-showline-count 1)
2164
2165(defvar ps-background-pages nil)
2166(defvar ps-background-all-pages nil)
2167(defvar ps-background-text-count 0)
2168(defvar ps-background-image-count 0)
1780 2169
1781(defvar ps-current-font 0) 2170(defvar ps-current-font 0)
1782(defvar ps-current-underline-p nil)
1783(defvar ps-default-color (if ps-print-color-p ps-default-fg)) ; black 2171(defvar ps-default-color (if ps-print-color-p ps-default-fg)) ; black
1784(defvar ps-current-color ps-default-color) 2172(defvar ps-current-color ps-default-color)
1785(defvar ps-current-bg nil) 2173(defvar ps-current-bg nil)
@@ -1803,11 +2191,11 @@ StandardEncoding 46 82 getinterval aload pop
1803;; are turned on. This is a pretty clumsy way of handling it, but 2191;; are turned on. This is a pretty clumsy way of handling it, but
1804;; it'll do for now. 2192;; it'll do for now.
1805 2193
1806(defvar ps-header-font) 2194(defvar ps-header-font nil)
1807(defvar ps-header-title-font) 2195(defvar ps-header-title-font nil)
1808 2196
1809(defvar ps-header-line-height) 2197(defvar ps-header-line-height nil)
1810(defvar ps-header-title-line-height) 2198(defvar ps-header-title-line-height nil)
1811(defvar ps-header-pad 0 2199(defvar ps-header-pad 0
1812 "Vertical and horizontal space in points (1/72 inch) between the header frame 2200 "Vertical and horizontal space in points (1/72 inch) between the header frame
1813and the text it contains.") 2201and the text it contains.")
@@ -1817,7 +2205,7 @@ and the text it contains.")
1817(defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims)) 2205(defmacro ps-page-dimensions-get-width (dims) `(nth 0 ,dims))
1818(defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims)) 2206(defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
1819 2207
1820(defvar ps-landscape-page-height) 2208(defvar ps-landscape-page-height nil)
1821 2209
1822(defvar ps-print-width nil) 2210(defvar ps-print-width nil)
1823(defvar ps-print-height nil) 2211(defvar ps-print-height nil)
@@ -1831,11 +2219,262 @@ and the text it contains.")
1831 2219
1832(defvar ps-print-color-scale nil) 2220(defvar ps-print-color-scale nil)
1833 2221
2222
2223;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2224;; Internal Variables
2225
2226
2227(defvar ps-print-face-extension-alist nil
2228 "Alist of symbolic faces with extension features (box, outline, etc).
2229An element of this list has the following form:
2230
2231 (FACE . [BITS FG BG])
2232
2233 FACE is a symbol denoting a face name
2234 BITS is a bit vector, where each bit correspond
2235 to a feature (bold, underline, etc)
2236 (see documentation for `ps-print-face-map-alist')
2237 FG foreground color (string or nil)
2238 BG background color (string or nil)
2239
2240This list should not be handled directly, but through `ps-new-faces',
2241`ps-extend-face' and `ps-extend-face-list'.
2242See documentation for `ps-extend-face' for valid extension symbol.
2243See also `font-lock-face-attributes'.")
2244
2245
2246(defconst ps-print-face-map-alist
2247 '((bold . 1)
2248 (italic . 2)
2249 (underline . 4)
2250 (strikeout . 8)
2251 (overline . 16)
2252 (shadow . 32)
2253 (box . 64)
2254 (outline . 128))
2255 "Alist of all features and the corresponding bit mask.
2256Each symbol correspond to one bit in a bit vector.")
2257
2258
2259;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2260;; Creating and Remapping Faces
2261
2262
2263(require 'font-lock)
2264
2265
2266;; The definition below is necessary because some emacs variant does not
2267;; define it on font-lock package.
2268
2269(defvar font-lock-face-attributes nil)
2270
2271
2272;;;###autoload
2273(defun ps-new-faces (face-screen &optional face-extension override-p merge-p)
2274 "Create new faces from FACE-SCREEN.
2275
2276The FACE-SCREEN elements are added to `font-lock-face-attributes'.
2277If optional OVERRIDE-P is non-nil, faces that already exist in
2278`font-lock-face-attributes' are overrided.
2279
2280If optional MERGE-p is non-nil, extensions in FACE-EXTENSION are merged with
2281face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2282
2283The arguments FACE-SCREEN and FACE-EXTENSION are lists whose elements are:
2284
2285 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2286
2287FACE-NAME is a face name.
2288
2289FOREGROUND and BACKGROUND may be nil or a string that denotes the
2290foreground and background colors respectively.
2291
2292EXTENSION is some valid extension symbol (see `ps-extend-face')."
2293 (let ((mapfun (if override-p
2294 '(lambda (face)
2295 (let ((face-attributes (ps-extension-to-screen-face face)))
2296 (font-lock-make-face face-attributes)
2297 (ps-override-list 'font-lock-face-attributes
2298 face-attributes)
2299 (ps-override-list 'ps-print-face-extension-alist
2300 (ps-extension-to-bit-face face))))
2301 '(lambda (face)
2302 (let ((face-attributes (ps-extension-to-screen-face face)))
2303 (font-lock-make-face face-attributes)
2304 (add-to-list 'font-lock-face-attributes
2305 face-attributes)
2306 (add-to-list 'ps-print-face-extension-alist
2307 (ps-extension-to-bit-face face))))
2308 ))
2309 maplist)
2310 (mapcar mapfun face-screen)
2311 (ps-extend-face-list face-extension merge-p)))
2312
2313
2314(defun ps-override-list (sym-list element)
2315 (let ((maplist (assq (car element) (symbol-value sym-list))))
2316 (if maplist
2317 (setcdr maplist (cdr element))
2318 (set sym-list (cons element (symbol-value sym-list)))
2319 )))
2320
2321
2322(defun ps-extension-to-bit-face (face-extension)
2323 (cons (nth 0 face-extension)
2324 (vector (ps-extension-bit face-extension)
2325 (nth 1 face-extension)
2326 (nth 2 face-extension))))
2327
2328
2329(defun ps-extension-to-screen-face (face)
2330 (let ((face-name (nth 0 face))
2331 (face-foreground (nth 1 face))
2332 (face-background (nth 2 face))
2333 (face-attributes (nthcdr 3 face)))
2334 (list face-name face-foreground face-background
2335 (and (memq 'bold face-attributes) t)
2336 (and (memq 'italic face-attributes) t)
2337 (and (memq 'underline face-attributes) t))))
2338
2339
2340;;;###autoload
2341(defun ps-extend-face-list (face-extension-list &optional merge-p)
2342 "Extend face in `ps-print-face-extension-alist'.
2343
2344If optional MERGE-p is non-nil, extensions in FACE-EXTENSION are merged with
2345face extension in `ps-print-face-extension-alist'; otherwise, overrides.
2346
2347The elements in FACE-EXTENSION-LIST is like those for `ps-extend-face'.
2348
2349See `ps-extend-face' for documentation."
2350 (while face-extension-list
2351 (ps-extend-face (car face-extension-list) merge-p)
2352 (setq face-extension-list (cdr face-extension-list))))
2353
2354
2355;;;###autoload
2356(defun ps-extend-face (face-extension &optional merge-p)
2357 "Extend face in `ps-print-face-extension-alist'.
2358
2359If optional MERGE-p is non-nil, extensions in FACE-EXTENSION are merged with
2360face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2361
2362The elements of FACE-EXTENSION list have the form:
2363
2364 (FACE-NAME FOREGROUND BACKGROUND EXTENSION...)
2365
2366FACE-NAME is a face name symbol.
2367
2368FOREGROUND and BACKGROUND may be nil or a string that denotes the
2369foreground and background colors respectively.
2370
2371EXTENSION is one of the following symbols:
2372 bold - use bold font.
2373 italic - use italic font.
2374 underline - put a line under text.
2375 strikeout - like underline, but the line is in middle of text.
2376 overline - like underline, but the line is over the text.
2377 shadow - text will have a shadow.
2378 box - text will be surrounded by a box.
2379 outline - only the text border font will be printed.
2380
2381If EXTENSION is any other symbol, it is ignored."
2382 (let* ((face-name (nth 0 face-extension))
2383 (foreground (nth 1 face-extension))
2384 (background (nth 2 face-extension))
2385 (ps-face (cdr (assq face-name ps-print-face-extension-alist)))
2386 (face-vector (or ps-face (vector 0 nil nil)))
2387 (face-bit (ps-extension-bit face-extension)))
2388 ;; extend face
2389 (aset face-vector 0 (if merge-p
2390 (logior (aref face-vector 0) face-bit)
2391 face-bit))
2392 (and foreground (stringp foreground) (aset face-vector 1 foreground))
2393 (and background (stringp background) (aset face-vector 2 background))
2394 ;; if face does not exist, insert it
2395 (or ps-face
2396 (setq ps-print-face-extension-alist
2397 (cons (cons face-name face-vector)
2398 ps-print-face-extension-alist)))))
2399
2400
2401(defun ps-extension-bit (face-extension)
2402 (let ((face-bit 0))
2403 ;; map valid symbol extension to bit vector
2404 (setq face-extension (cdr (cdr face-extension)))
2405 (while (setq face-extension (cdr face-extension))
2406 (setq face-bit (logior face-bit
2407 (or (cdr (assq (car face-extension)
2408 ps-print-face-map-alist))
2409 0))))
2410 face-bit))
2411
2412
2413;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2414;; Internal functions and variables
2415
2416
2417(defun ps-print-without-faces (from to &optional filename)
2418 (ps-generate (current-buffer) from to 'ps-generate-postscript)
2419 (ps-do-despool filename))
2420
2421
2422(defun ps-spool-without-faces (from to)
2423 (ps-generate (current-buffer) from to 'ps-generate-postscript))
2424
2425
2426(defun ps-print-with-faces (from to &optional filename)
2427 (ps-initialize-faces)
2428 (ps-generate (current-buffer) from to 'ps-generate-postscript-with-faces)
2429 (ps-do-despool filename))
2430
2431
2432(defun ps-spool-with-faces (from to)
2433 (ps-initialize-faces)
2434 (ps-generate (current-buffer) from to 'ps-generate-postscript-with-faces))
2435
2436
2437(defvar ps-initialize-faces nil)
2438
2439
2440(defun ps-initialize-faces ()
2441 (or ps-initialize-faces
2442 (progn
2443 (setq ps-initialize-faces t)
2444 (mapcar 'ps-map-font-lock font-lock-face-attributes))))
2445
2446
2447(defun ps-map-font-lock (face)
2448 (let* ((face-map (ps-screen-to-bit-face face))
2449 (ps-face-bit (cdr (assq (car face-map)
2450 ps-print-face-extension-alist))))
2451 (if ps-face-bit
2452 ;; if face exists, merge both
2453 (let ((face-bit (cdr face-map)))
2454 (aset ps-face-bit 0 (logior (aref ps-face-bit 0) (aref face-bit 0)))
2455 (or (aref ps-face-bit 1) (aset ps-face-bit 1 (aref face-bit 1)))
2456 (or (aref ps-face-bit 2) (aset ps-face-bit 2 (aref face-bit 2))))
2457 ;; if face does not exist, insert it
2458 (setq ps-print-face-extension-alist
2459 (cons face-map ps-print-face-extension-alist))
2460 )))
2461
2462
2463(defun ps-screen-to-bit-face (face)
2464 (let ((face-name (car face))
2465 (face-foreground (nth 1 face))
2466 (face-background (nth 2 face))
2467 (face-bit (logior (if (nth 3 face) 1 0) ; bold
2468 (if (nth 4 face) 2 0) ; italic
2469 (if (nth 5 face) 4 0)))) ; underline
2470 (cons face-name (vector face-bit face-foreground face-background))))
2471
2472
1834;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2473;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1835;; Internal functions 2474;; Internal functions
1836 2475
1837(defun ps-line-lengths-internal () 2476(defun ps-line-lengths-internal ()
1838 "Display the correspondance between a line length and a font size, 2477 "Display the correspondence between a line length and a font size,
1839using the current ps-print setup. 2478using the current ps-print setup.
1840Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head" 2479Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1841 (let ((buf (get-buffer-create "*Line-lengths*")) 2480 (let ((buf (get-buffer-create "*Line-lengths*"))
@@ -1873,7 +2512,7 @@ Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
1873 (display-buffer buf 'not-this-window))) 2512 (display-buffer buf 'not-this-window)))
1874 2513
1875(defun ps-nb-pages (nb-lines) 2514(defun ps-nb-pages (nb-lines)
1876 "Display an approximate correspondance between a font size and the number 2515 "Display an approximate correspondence between a font size and the number
1877of pages the number of lines would require to print 2516of pages the number of lines would require to print
1878using the current ps-print setup." 2517using the current ps-print setup."
1879 (let ((buf (get-buffer-create "*Nb-Pages*")) 2518 (let ((buf (get-buffer-create "*Nb-Pages*"))
@@ -1979,7 +2618,7 @@ using the current ps-print setup."
1979 (error "`ps-paper-type' must be one of:\n%s" 2618 (error "`ps-paper-type' must be one of:\n%s"
1980 (mapcar 'car ps-page-dimensions-database))) 2619 (mapcar 'car ps-page-dimensions-database)))
1981 ((< ps-number-of-columns 1) 2620 ((< ps-number-of-columns 1)
1982 (error "The number of columns %d should not be negative"))) 2621 (error "The number of columns %d should not be negative" ps-number-of-columns)))
1983 2622
1984 (ps-select-font) 2623 (ps-select-font)
1985 (ps-select-header-font) 2624 (ps-select-header-font)
@@ -2107,6 +2746,9 @@ page-height == bm + print-height + tm - ho - hh
2107(defun ps-output-string (string) 2746(defun ps-output-string (string)
2108 (ps-output t string)) 2747 (ps-output t string))
2109 2748
2749(defun ps-output-list (the-list)
2750 (mapcar 'ps-output the-list))
2751
2110(defun ps-flush-output () 2752(defun ps-flush-output ()
2111 (save-excursion 2753 (save-excursion
2112 (set-buffer ps-spool-buffer) 2754 (set-buffer ps-spool-buffer)
@@ -2122,12 +2764,10 @@ page-height == bm + print-height + tm - ho - hh
2122 2764
2123(defun ps-insert-file (fname) 2765(defun ps-insert-file (fname)
2124 (ps-flush-output) 2766 (ps-flush-output)
2125
2126 ;; Check to see that the file exists and is readable; if not, throw 2767 ;; Check to see that the file exists and is readable; if not, throw
2127 ;; and error. 2768 ;; an error.
2128 (if (not (file-readable-p fname)) 2769 (or (file-readable-p fname)
2129 (error "Could not read file `%s'" fname)) 2770 (error "Could not read file `%s'" fname))
2130
2131 (save-excursion 2771 (save-excursion
2132 (set-buffer ps-spool-buffer) 2772 (set-buffer ps-spool-buffer)
2133 (goto-char (point-max)) 2773 (goto-char (point-max))
@@ -2173,27 +2813,170 @@ page-height == bm + print-height + tm - ho - hh
2173(defun ps-output-boolean (name bool) 2813(defun ps-output-boolean (name bool)
2174 (ps-output (format "/%s %s def\n" name (if bool "true" "false")))) 2814 (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
2175 2815
2816(defsubst ps-count-lines (from to)
2817 (+ (count-lines from to)
2818 (save-excursion (goto-char to)
2819 (if (= (current-column) 0) 1 0))))
2820
2821
2822(defun ps-background-pages (page-list func)
2823 (if page-list
2824 (mapcar
2825 '(lambda (pages)
2826 (let ((start (if (consp pages) (car pages) pages))
2827 (end (if (consp pages) (cdr pages) pages)))
2828 (and (integerp start) (integerp end) (<= start end)
2829 (add-to-list 'ps-background-pages (vector start end func)))))
2830 page-list)
2831 (setq ps-background-all-pages (cons func ps-background-all-pages))))
2832
2833
2834(defun ps-get-boundingbox ()
2835 (save-excursion
2836 (set-buffer ps-spool-buffer)
2837 (save-excursion
2838 (if (re-search-forward
2839 "^%%BoundingBox:\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)\\s-+\\([0-9.]+\\)"
2840 nil t)
2841 (vector (string-to-number ; lower x
2842 (buffer-substring (match-beginning 1) (match-end 1)))
2843 (string-to-number ; lower y
2844 (buffer-substring (match-beginning 2) (match-end 2)))
2845 (string-to-number ; upper x
2846 (buffer-substring (match-beginning 3) (match-end 3)))
2847 (string-to-number ; upper y
2848 (buffer-substring (match-beginning 4) (match-end 4))))
2849 (vector 0 0 0 0)))))
2850
2851
2852;; Emacs understands the %f format; we'll use it to limit color RGB values
2853;; to three decimals to cut down some on the size of the PostScript output.
2854;; Lucid emacsen will have to make do with %s (princ) for floats.
2855
2856(defvar ps-float-format (if (eq ps-print-emacs-type 'emacs)
2857 "%0.3f " ; emacs
2858 "%s ")) ; Lucid emacsen
2859
2860
2861(defun ps-float-format (value &optional default)
2862 (let ((literal (or value default)))
2863 (if literal
2864 (format (if (numberp literal)
2865 ps-float-format
2866 "%s ")
2867 literal)
2868 " ")))
2869
2870
2871(defun ps-background-text ()
2872 (mapcar
2873 '(lambda (text)
2874 (setq ps-background-text-count (1+ ps-background-text-count))
2875 (ps-output (format "/ShowBackText-%d {\n" ps-background-text-count))
2876 (ps-output-string (nth 0 text)) ; text
2877 (ps-output
2878 "\n"
2879 (ps-float-format (nth 4 text) 200.0) ; font size
2880 (format "/%s " (or (nth 3 text) "Times-Roman")) ; font name
2881 (ps-float-format (nth 6 text)
2882 "PrintHeight PrintPageWidth atan") ; rotation
2883 (ps-float-format (nth 5 text) 0.85) ; gray
2884 (ps-float-format (nth 1 text) "0") ; x position
2885 (ps-float-format (nth 2 text) "BottomMargin") ; y position
2886 "\nShowBackText} def\n")
2887 (ps-background-pages (nthcdr 7 text) ; page list
2888 (format "ShowBackText-%d\n"
2889 ps-background-text-count)))
2890 ps-print-background-text))
2891
2892
2893(defun ps-background-image ()
2894 (mapcar
2895 '(lambda (image)
2896 (let ((image-file (expand-file-name (nth 0 image))))
2897 (if (file-readable-p image-file)
2898 (progn
2899 (setq ps-background-image-count (1+ ps-background-image-count))
2900 (ps-output
2901 (format "/ShowBackImage-%d {\n--back-- " ps-background-image-count)
2902 (ps-float-format (nth 5 image) 0.0) ; rotation
2903 (ps-float-format (nth 3 image) 1.0) ; x scale
2904 (ps-float-format (nth 4 image) 1.0) ; y scale
2905 (ps-float-format (nth 1 image) ; x position
2906 "PrintPageWidth 2 div")
2907 (ps-float-format (nth 2 image) ; y position
2908 "PrintHeight 2 div BottomMargin add")
2909 "\nBeginBackImage\n")
2910 (ps-insert-file image-file)
2911 ;; coordinate adjustment to centralize image
2912 ;; around x and y position
2913 (let ((box (ps-get-boundingbox)))
2914 (save-excursion
2915 (set-buffer ps-spool-buffer)
2916 (save-excursion
2917 (if (re-search-backward "^--back--" nil t)
2918 (replace-match
2919 (format "%s %s"
2920 (ps-float-format
2921 (- (+ (/ (- (aref box 2) (aref box 0)) 2.0)
2922 (aref box 0))))
2923 (ps-float-format
2924 (- (+ (/ (- (aref box 3) (aref box 1)) 2.0)
2925 (aref box 1)))))
2926 t)))))
2927 (ps-output "\nEndBackImage} def\n")
2928 (ps-background-pages (nthcdr 6 image) ; page list
2929 (format "ShowBackImage-%d\n"
2930 ps-background-image-count))))))
2931 ps-print-background-image))
2932
2933
2934(defun ps-background ()
2935 (let (has-local-background)
2936 (mapcar '(lambda (range)
2937 (and (<= (aref range 0) ps-page-count)
2938 (<= ps-page-count (aref range 1))
2939 (if has-local-background
2940 (ps-output (aref range 2))
2941 (setq has-local-background t)
2942 (ps-output "/printLocalBackground {\n"
2943 (aref range 2)))))
2944 ps-background-pages)
2945 (and has-local-background (ps-output "} def\n"))))
2946
2947
2176(defun ps-begin-file () 2948(defun ps-begin-file ()
2177 (ps-get-page-dimensions) 2949 (ps-get-page-dimensions)
2178 (setq ps-showpage-count 0) 2950 (setq ps-showpage-count 0
2951 ps-showline-count 1
2952 ps-background-text-count 0
2953 ps-background-image-count 0
2954 ps-background-pages nil
2955 ps-background-all-pages nil)
2179 2956
2180 (ps-output ps-adobe-tag) 2957 (ps-output ps-adobe-tag)
2181 (ps-output "%%Title: " (buffer-name) "\n") ;Take job name from name of 2958 (ps-output "%%Title: " (buffer-name)) ;Take job name from name of
2182 ;first buffer printed 2959 ;first buffer printed
2183 (ps-output "%%Creator: " (user-full-name) "\n") 2960 (ps-output "\n%%Creator: " (user-full-name))
2184 (ps-output "%%CreationDate: " 2961 (ps-output "\n%%CreationDate: "
2185 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) "\n") 2962 (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy)
2186 (ps-output "%% DocumentFonts: " 2963 "\n%%Orientation: "
2964 (if ps-landscape-mode "Landscape" "Portrait"))
2965 (ps-output "\n%% DocumentFonts: Times-Roman Times-Italic "
2187 ps-font " " ps-font-bold " " ps-font-italic " " 2966 ps-font " " ps-font-bold " " ps-font-italic " "
2188 ps-font-bold-italic " " 2967 ps-font-bold-italic " "
2189 ps-header-font " " ps-header-title-font "\n") 2968 ps-header-font " " ps-header-title-font)
2190 (ps-output "%%Pages: (atend)\n") 2969 (ps-output "\n%%Pages: (atend)\n")
2191 (ps-output "%%EndComments\n\n") 2970 (ps-output "%%EndComments\n\n")
2192 2971
2193 (ps-output-boolean "LandscapeMode" ps-landscape-mode) 2972 (ps-output-boolean "LandscapeMode" ps-landscape-mode)
2194 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns)) 2973 (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns))
2195 2974
2196 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height)) 2975 (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height))
2976 (ps-output (format "/PrintPageWidth %s def\n"
2977 (- (* (+ ps-print-width ps-inter-column)
2978 ps-number-of-columns)
2979 ps-inter-column)))
2197 (ps-output (format "/PrintWidth %s def\n" ps-print-width)) 2980 (ps-output (format "/PrintWidth %s def\n" ps-print-width))
2198 (ps-output (format "/PrintHeight %s def\n" ps-print-height)) 2981 (ps-output (format "/PrintHeight %s def\n" ps-print-height))
2199 2982
@@ -2211,10 +2994,31 @@ page-height == bm + print-height + tm - ho - hh
2211 (ps-output-boolean "ShowNofN" ps-show-n-of-n) 2994 (ps-output-boolean "ShowNofN" ps-show-n-of-n)
2212 (ps-output-boolean "Duplex" ps-spool-duplex) 2995 (ps-output-boolean "Duplex" ps-spool-duplex)
2213 2996
2214 (ps-output (format "/LineHeight %s def\n" ps-line-height)) 2997 (ps-output (format "/LineHeight %s def\n" ps-line-height)
2998 (format "/LinesPerColumn %d def\n"
2999 (round (/ (+ (if ps-print-header
3000 (- ps-print-height (ps-header-height))
3001 ps-print-height)
3002 (* ps-line-height 0.45))
3003 ps-line-height))))
3004
3005 (ps-output-boolean "Zebra" ps-zebra-stripe)
3006 (ps-output (format "/NumberOfZebra %d def\n" ps-number-of-zebra))
3007
3008 (ps-output-boolean "PrintLineNumber" ps-line-number)
3009 (ps-output (format "/Lines %d def\n" (ps-count-lines (point-min) (point-max))))
3010
3011 (ps-background-text)
3012 (ps-background-image)
3013 (setq ps-background-all-pages (nreverse ps-background-all-pages)
3014 ps-background-pages (nreverse ps-background-pages))
2215 3015
2216 (ps-output ps-print-prologue-1) 3016 (ps-output ps-print-prologue-1)
2217 3017
3018 (ps-output "/printGlobalBackground {\n")
3019 (ps-output-list ps-background-all-pages)
3020 (ps-output "} def\n/printLocalBackground {\n} def\n")
3021
2218 ;; Header fonts 3022 ;; Header fonts
2219 (ps-output ; /h0 14 /Helvetica-Bold Font 3023 (ps-output ; /h0 14 /Helvetica-Bold Font
2220 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font)) 3024 (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font))
@@ -2248,16 +3052,25 @@ page-height == bm + print-height + tm - ho - hh
2248 ;; Indulge Jack this other little easter egg: 3052 ;; Indulge Jack this other little easter egg:
2249 ((string= (buffer-name) "sokoban.el") 3053 ((string= (buffer-name) "sokoban.el")
2250 "Super! C'est sokoban.el!") 3054 "Super! C'est sokoban.el!")
2251 (t (buffer-name)))) 3055 (t (concat
3056 (buffer-name)
3057 (and (buffer-modified-p) " (unsaved)")))))
2252 3058
2253(defun ps-begin-job () 3059(defun ps-begin-job ()
2254 (setq ps-page-count 0)) 3060 (setq ps-page-count 0))
2255 3061
2256(defun ps-end-file () 3062(defun ps-end-file ()
2257 (ps-output "\nEndDoc\n\n") 3063 (ps-output "\n%%Trailer\n")
2258 (ps-output "%%Trailer\n")
2259 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count) 3064 (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count)
2260 ps-number-of-columns))))) 3065 ps-number-of-columns))))
3066 (ps-output "\nEndDoc\n\n%%EOF\n"))
3067
3068
3069(defun ps-header-height ()
3070 (+ ps-header-title-line-height
3071 (* ps-header-line-height (1- ps-header-lines))
3072 (* 2 ps-header-pad)))
3073
2261 3074
2262(defun ps-next-page () 3075(defun ps-next-page ()
2263 (ps-end-page) 3076 (ps-end-page)
@@ -2276,7 +3089,8 @@ page-height == bm + print-height + tm - ho - hh
2276 (1+ (/ ps-page-count ps-number-of-columns))))) 3089 (1+ (/ ps-page-count ps-number-of-columns)))))
2277 3090
2278 (ps-output "BeginDSCPage\n") 3091 (ps-output "BeginDSCPage\n")
2279 (ps-output (format "/PageNumber %d def\n" (incf ps-page-count))) 3092 (ps-output (format "/LineNumber %d def\n" ps-showline-count)
3093 (format "/PageNumber %d def\n" (incf ps-page-count)))
2280 (ps-output "/PageCount 0 def\n") 3094 (ps-output "/PageCount 0 def\n")
2281 3095
2282 (when ps-print-header 3096 (when ps-print-header
@@ -2284,11 +3098,12 @@ page-height == bm + print-height + tm - ho - hh
2284 (ps-generate-header "HeaderLinesRight" ps-right-header) 3098 (ps-generate-header "HeaderLinesRight" ps-right-header)
2285 (ps-output (format "%d SetHeaderLines\n" ps-header-lines))) 3099 (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
2286 3100
3101 (ps-background)
3102
2287 (ps-output "BeginPage\n") 3103 (ps-output "BeginPage\n")
2288 (ps-set-font ps-current-font) 3104 (ps-set-font ps-current-font)
2289 (ps-set-bg ps-current-bg) 3105 (ps-set-bg ps-current-bg)
2290 (ps-set-color ps-current-color) 3106 (ps-set-color ps-current-color))
2291 (ps-set-underline ps-current-underline-p))
2292 3107
2293(defun ps-end-page () 3108(defun ps-end-page ()
2294 (setq ps-showpage-count (+ 1 ps-showpage-count)) 3109 (setq ps-showpage-count (+ 1 ps-showpage-count))
@@ -2305,6 +3120,7 @@ EndPage
2305EndDSCPage\n")) 3120EndDSCPage\n"))
2306 3121
2307(defun ps-next-line () 3122(defun ps-next-line ()
3123 (setq ps-showline-count (1+ ps-showline-count))
2308 (if (< ps-height-remaining ps-line-height) 3124 (if (< ps-height-remaining ps-line-height)
2309 (ps-next-page) 3125 (ps-next-page)
2310 (setq ps-width-remaining ps-print-width) 3126 (setq ps-width-remaining ps-print-width)
@@ -2344,7 +3160,6 @@ EndDSCPage\n"))
2344(defun ps-basic-plot-whitespace (from to &optional bg-color) 3160(defun ps-basic-plot-whitespace (from to &optional bg-color)
2345 (let* ((wrappoint (ps-find-wrappoint from to ps-space-width)) 3161 (let* ((wrappoint (ps-find-wrappoint from to ps-space-width))
2346 (to (car wrappoint))) 3162 (to (car wrappoint)))
2347
2348 (ps-output (format "%d W\n" (- to from))) 3163 (ps-output (format "%d W\n" (- to from)))
2349 wrappoint)) 3164 wrappoint))
2350 3165
@@ -2390,12 +3205,11 @@ EndDSCPage\n"))
2390 (nth 1 ps-current-color) (nth 2 ps-current-color)) 3205 (nth 1 ps-current-color) (nth 2 ps-current-color))
2391 " FG\n")) 3206 " FG\n"))
2392 3207
2393(defun ps-set-underline (underline-p)
2394 (ps-output (if underline-p "true" "false") " UL\n")
2395 (setq ps-current-underline-p underline-p))
2396 3208
2397(defun ps-plot-region (from to font fg-color &optional bg-color underline-p) 3209(defvar ps-current-effect 0)
2398 3210
3211
3212(defun ps-plot-region (from to font &optional fg-color bg-color effects)
2399 (if (not (equal font ps-current-font)) 3213 (if (not (equal font ps-current-font))
2400 (ps-set-font font)) 3214 (ps-set-font font))
2401 3215
@@ -2407,45 +3221,68 @@ EndDSCPage\n"))
2407 (if (not (equal bg-color ps-current-bg)) 3221 (if (not (equal bg-color ps-current-bg))
2408 (ps-set-bg bg-color)) 3222 (ps-set-bg bg-color))
2409 3223
2410 ;; Toggle underlining if different. 3224 ;; Specify effects (underline, overline, box, etc)
2411 (if (not (equal underline-p ps-current-underline-p)) 3225 (cond
2412 (ps-set-underline underline-p)) 3226 ((not (integerp effects))
3227 (ps-output "0 EF\n")
3228 (setq ps-current-effect 0))
3229 ((/= effects ps-current-effect)
3230 (ps-output (number-to-string effects) " EF\n")
3231 (setq ps-current-effect effects)))
2413 3232
2414 ;; Starting at the beginning of the specified region... 3233 ;; Starting at the beginning of the specified region...
2415 (save-excursion 3234 (save-excursion
2416 (goto-char from) 3235 (goto-char from)
2417 3236
2418 ;; ...break the region up into chunks separated by tabs, linefeeds, 3237 ;; ...break the region up into chunks separated by tabs, linefeeds,
2419 ;; and pagefeeds, and plot each chunk. 3238 ;; pagefeeds, control characters, and plot each chunk.
2420 (while (< from to) 3239 (while (< from to)
2421 (if (re-search-forward "[\t\n\f]" to t) 3240 (if (re-search-forward "[\000-\037\177-\377]" to t)
2422 (let ((match (char-after (match-beginning 0)))) 3241 ;; region whith some control characters
2423 (cond 3242 (let ((match (char-after (match-beginning 0))))
2424 ((= match ?\t) 3243 (if (= match ?\t) ; tab
2425 (let ((linestart 3244 (let ((linestart
2426 (save-excursion (beginning-of-line) (point)))) 3245 (save-excursion (beginning-of-line) (point))))
2427 (ps-plot 'ps-basic-plot-string from (- (point) 1) 3246 (ps-plot 'ps-basic-plot-string from (- (point) 1)
2428 bg-color) 3247 bg-color)
2429 (forward-char -1) 3248 (forward-char -1)
2430 (setq from (+ linestart (current-column))) 3249 (setq from (+ linestart (current-column)))
2431 (if (re-search-forward "[ \t]+" to t) 3250 (if (re-search-forward "[ \t]+" to t)
2432 (ps-plot 'ps-basic-plot-whitespace 3251 (ps-plot 'ps-basic-plot-whitespace
2433 from (+ linestart (current-column)) 3252 from (+ linestart (current-column))
2434 bg-color)))) 3253 bg-color)))
2435 3254 ;; any other control character except tab
2436 ((= match ?\n) 3255 (ps-plot 'ps-basic-plot-string from (- (point) 1) bg-color)
2437 (ps-plot 'ps-basic-plot-string from (- (point) 1) 3256 (cond
2438 bg-color) 3257 ((= match ?\n) ; newline
2439 (ps-next-line) 3258 (ps-next-line))
2440 ) 3259
2441 3260 ((= match ?\f) ; form feed
2442 ((= match ?\f) 3261 (ps-next-page))
2443 (ps-plot 'ps-basic-plot-string from (- (point) 1) 3262
2444 bg-color) 3263 ((<= match ?\037) ; characters from ^@ to ^_
2445 (ps-next-page))) 3264 (ps-control-character (format "^%c" (+ match ?@))))
2446 (setq from (point))) 3265
2447 (ps-plot 'ps-basic-plot-string from to bg-color) 3266 ((= match ?\177) ; del (127) is printed ^?
2448 (setq from to))))) 3267 (ps-control-character "^?"))
3268
3269 (t ; characters from 128 to 255
3270 (ps-control-character (format "\\%o" match)))))
3271 (setq from (point)))
3272 ;; region without control characters
3273 (ps-plot 'ps-basic-plot-string from to bg-color)
3274 (setq from to)))))
3275
3276(defun ps-control-character (str)
3277 (let* ((from (1- (point)))
3278 (len (length str))
3279 (to (+ from len))
3280 (wrappoint (ps-find-wrappoint from to ps-avg-char-width)))
3281 (if (< (car wrappoint) to)
3282 (ps-continue-line))
3283 (setq ps-width-remaining (- ps-width-remaining (* len ps-avg-char-width)))
3284 (ps-output-string str)
3285 (ps-output " S\n")))
2449 3286
2450(defun ps-color-value (x-color-value) 3287(defun ps-color-value (x-color-value)
2451 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval. 3288 ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
@@ -2458,42 +3295,64 @@ EndDSCPage\n"))
2458 (pixel-components x-color)) 3295 (pixel-components x-color))
2459 (t (error "No available function to determine X color values.")))) 3296 (t (error "No available function to determine X color values."))))
2460 3297
3298
3299(defun ps-get-face (face)
3300 "Return face description on `ps-print-face-extension-alist'.
3301
3302If FACE is not in `ps-print-face-extension-alist',
3303insert it and return the description.
3304
3305If FACE is not a valid face name, it is used default face."
3306 (or (assq face ps-print-face-extension-alist)
3307 (let* ((the-face (if (facep face) face 'default))
3308 (font (face-font the-face t))
3309 (new-face
3310 (cons the-face
3311 (vector
3312 (logior (if (memq 'bold font) 1 0)
3313 (if (memq 'italic font) 2 0)
3314 (if (face-underline-p the-face) 4 0))
3315 (face-foreground the-face)
3316 (face-background the-face)))))
3317 (or (and (eq the-face 'default)
3318 (assq the-face ps-print-face-extension-alist))
3319 (setq ps-print-face-extension-alist
3320 (cons new-face
3321 ps-print-face-extension-alist)))
3322 new-face)))
3323
3324
2461(defun ps-face-attributes (face) 3325(defun ps-face-attributes (face)
2462 (let ((differs (face-differs-from-default-p face))) 3326 (let* ((face-vector (cdr (ps-get-face face)))
2463 (list (memq face ps-ref-bold-faces) 3327 (effects (logior (aref face-vector 0)
2464 (memq face ps-ref-italic-faces) 3328 (if (memq face ps-ref-bold-faces) 1 0)
2465 (memq face ps-ref-underlined-faces) 3329 (if (memq face ps-ref-italic-faces) 2 0)
2466 (and differs (face-foreground face)) 3330 (if (memq face ps-ref-underlined-faces) 4 0))))
2467 (and differs (face-background face))))) 3331 (vector effects (aref face-vector 1) (aref face-vector 2))))
3332
2468 3333
2469(defun ps-face-attribute-list (face-or-list) 3334(defun ps-face-attribute-list (face-or-list)
2470 (if (listp face-or-list) 3335 (if (listp face-or-list)
2471 (let (bold-p italic-p underline-p foreground background face-attr face) 3336 ;; list of faces
3337 (let ((effects 0) foreground background face-attr face)
2472 (while face-or-list 3338 (while face-or-list
2473 (setq face (car face-or-list)) 3339 (setq face (car face-or-list)
2474 (setq face-attr (ps-face-attributes face)) 3340 face-attr (ps-face-attributes face)
2475 (setq bold-p (or bold-p (nth 0 face-attr))) 3341 effects (logior effects (aref face-attr 0)))
2476 (setq italic-p (or italic-p (nth 1 face-attr))) 3342 (or foreground (setq foreground (aref face-attr 1)))
2477 (setq underline-p (or underline-p (nth 2 face-attr))) 3343 (or background (setq background (aref face-attr 2)))
2478 (if foreground
2479 nil
2480 (setq foreground (nth 3 face-attr)))
2481 (if background
2482 nil
2483 (setq background (nth 4 face-attr)))
2484 (setq face-or-list (cdr face-or-list))) 3344 (setq face-or-list (cdr face-or-list)))
2485 (list bold-p italic-p underline-p foreground background)) 3345 (vector effects foreground background))
2486 3346 ;; simple face
2487 (ps-face-attributes face-or-list))) 3347 (ps-face-attributes face-or-list)))
2488 3348
3349
2489(defun ps-plot-with-face (from to face) 3350(defun ps-plot-with-face (from to face)
2490 (if face 3351 (if face
2491 (let* ((face-attr (ps-face-attribute-list face)) 3352 (let* ((face-bit (ps-face-attribute-list face))
2492 (bold-p (nth 0 face-attr)) 3353 (effect (aref face-bit 0))
2493 (italic-p (nth 1 face-attr)) 3354 (foreground (aref face-bit 1))
2494 (underline-p (nth 2 face-attr)) 3355 (background (aref face-bit 2))
2495 (foreground (nth 3 face-attr))
2496 (background (nth 4 face-attr))
2497 (fg-color (if (and ps-print-color-p foreground) 3356 (fg-color (if (and ps-print-color-p foreground)
2498 (mapcar 'ps-color-value 3357 (mapcar 'ps-color-value
2499 (ps-color-values foreground)) 3358 (ps-color-values foreground))
@@ -2501,15 +3360,10 @@ EndDSCPage\n"))
2501 (bg-color (if (and ps-print-color-p background) 3360 (bg-color (if (and ps-print-color-p background)
2502 (mapcar 'ps-color-value 3361 (mapcar 'ps-color-value
2503 (ps-color-values background))))) 3362 (ps-color-values background)))))
2504 (ps-plot-region from to 3363 (ps-plot-region from to (logand effect 3)
2505 (cond ((and bold-p italic-p) 3) 3364 fg-color bg-color (lsh effect -2)))
2506 (italic-p 2) 3365 (ps-plot-region from to 0))
2507 (bold-p 1) 3366 (goto-char to))
2508 (t 0))
2509; (or fg-color '(0.0 0.0 0.0))
2510 fg-color
2511 bg-color underline-p))
2512 (goto-char to)))
2513 3367
2514 3368
2515(defun ps-emacs-face-kind-p (face kind kind-regex kind-list) 3369(defun ps-emacs-face-kind-p (face kind kind-regex kind-list)
@@ -2519,7 +3373,6 @@ EndDSCPage\n"))
2519 ;; Check FACE defaults: 3373 ;; Check FACE defaults:
2520 (and (listp face-defaults) 3374 (and (listp face-defaults)
2521 (memq kind face-defaults)) 3375 (memq kind face-defaults))
2522
2523 ;; Check the user's preferences 3376 ;; Check the user's preferences
2524 (memq face kind-list)))) 3377 (memq face kind-list))))
2525 3378
@@ -2593,6 +3446,9 @@ EndDSCPage\n"))
2593 (lazy-lock-fontify-buffer)))) ; the old 3446 (lazy-lock-fontify-buffer)))) ; the old
2594 3447
2595(defun ps-generate-postscript-with-faces (from to) 3448(defun ps-generate-postscript-with-faces (from to)
3449 ;; Some initialization...
3450 (setq ps-current-effect 0)
3451
2596 ;; Build the reference lists of faces if necessary. 3452 ;; Build the reference lists of faces if necessary.
2597 (if (or ps-always-build-face-reference 3453 (if (or ps-always-build-face-reference
2598 ps-build-face-reference) 3454 ps-build-face-reference)
@@ -2612,178 +3468,182 @@ EndDSCPage\n"))
2612 (let ((face 'default) 3468 (let ((face 'default)
2613 (position to)) 3469 (position to))
2614 (ps-print-ensure-fontified from to) 3470 (ps-print-ensure-fontified from to)
2615 (cond ((or (eq ps-print-emacs-type 'lucid) 3471 (cond
2616 (eq ps-print-emacs-type 'xemacs)) 3472 ((or (eq ps-print-emacs-type 'lucid)
2617 ;; Build the list of extents... 3473 (eq ps-print-emacs-type 'xemacs))
2618 (let ((a (cons 'dummy nil)) 3474 ;; Build the list of extents...
2619 record type extent extent-list) 3475 (let ((a (cons 'dummy nil))
2620 (map-extents 'ps-mapper nil from to a) 3476 record type extent extent-list)
2621 (setq a (sort (cdr a) 'car-less-than-car)) 3477 (map-extents 'ps-mapper nil from to a)
2622 3478 (setq a (sort (cdr a) 'car-less-than-car))
2623 (setq extent-list nil) 3479
2624 3480 (setq extent-list nil)
2625 ;; Loop through the extents... 3481
2626 (while a 3482 ;; Loop through the extents...
2627 (setq record (car a)) 3483 (while a
2628 3484 (setq record (car a))
2629 (setq position (car record)) 3485
2630 (setq record (cdr record)) 3486 (setq position (car record))
2631 3487 (setq record (cdr record))
2632 (setq type (car record)) 3488
2633 (setq record (cdr record)) 3489 (setq type (car record))
2634 3490 (setq record (cdr record))
2635 (setq extent (car record)) 3491
2636 3492 (setq extent (car record))
2637 ;; Plot up to this record. 3493
2638 ;; XEmacs 19.12: for some reason, we're getting into a 3494 ;; Plot up to this record.
2639 ;; situation in which some of the records have 3495 ;; XEmacs 19.12: for some reason, we're getting into a
2640 ;; positions less than 'from'. Since we've narrowed 3496 ;; situation in which some of the records have
2641 ;; the buffer, this'll generate errors. This is a 3497 ;; positions less than 'from'. Since we've narrowed
2642 ;; hack, but don't call ps-plot-with-face unless from > 3498 ;; the buffer, this'll generate errors. This is a
2643 ;; point-min. 3499 ;; hack, but don't call ps-plot-with-face unless from >
2644 (if (and (>= from (point-min)) 3500 ;; point-min.
2645 (<= position (point-max))) 3501 (if (and (>= from (point-min))
2646 (ps-plot-with-face from position face)) 3502 (<= position (point-max)))
2647 3503 (ps-plot-with-face from position face))
2648 (cond 3504
2649 ((eq type 'push) 3505 (cond
2650 (if (extent-face extent) 3506 ((eq type 'push)
2651 (setq extent-list (sort (cons extent extent-list) 3507 (if (extent-face extent)
2652 'ps-extent-sorter)))) 3508 (setq extent-list (sort (cons extent extent-list)
2653 3509 'ps-extent-sorter))))
2654 ((eq type 'pull) 3510
2655 (setq extent-list (sort (delq extent extent-list) 3511 ((eq type 'pull)
2656 'ps-extent-sorter)))) 3512 (setq extent-list (sort (delq extent extent-list)
2657 3513 'ps-extent-sorter))))
2658 (setq face 3514
2659 (if extent-list 3515 (setq face
2660 (extent-face (car extent-list)) 3516 (if extent-list
2661 'default)) 3517 (extent-face (car extent-list))
2662 3518 'default))
2663 (setq from position) 3519
2664 (setq a (cdr a))))) 3520 (setq from position)
2665 3521 (setq a (cdr a)))))
2666 ((eq ps-print-emacs-type 'emacs) 3522
2667 (let ((property-change from) 3523 ((eq ps-print-emacs-type 'emacs)
2668 (overlay-change from)) 3524 (let ((property-change from)
2669 (while (< from to) 3525 (overlay-change from))
2670 (if (< property-change to) ; Don't search for property change 3526 (while (< from to)
3527 (if (< property-change to) ; Don't search for property change
2671 ; unless previous search succeeded. 3528 ; unless previous search succeeded.
2672 (setq property-change 3529 (setq property-change
2673 (next-property-change from nil to))) 3530 (next-property-change from nil to)))
2674 (if (< overlay-change to) ; Don't search for overlay change 3531 (if (< overlay-change to) ; Don't search for overlay change
2675 ; unless previous search succeeded. 3532 ; unless previous search succeeded.
2676 (setq overlay-change 3533 (setq overlay-change
2677 (min (next-overlay-change from) to))) 3534 (min (next-overlay-change from) to)))
2678 (setq position 3535 (setq position
2679 (min property-change overlay-change)) 3536 (min property-change overlay-change))
2680 ;; The code below is not quite correct, 3537 ;; The code below is not quite correct,
2681 ;; because a non-nil overlay invisible property 3538 ;; because a non-nil overlay invisible property
2682 ;; which is inactive according to the current value 3539 ;; which is inactive according to the current value
2683 ;; of buffer-invisibility-spec nonetheless overrides 3540 ;; of buffer-invisibility-spec nonetheless overrides
2684 ;; a face text property. 3541 ;; a face text property.
2685 (setq face 3542 (setq face
2686 (cond ((let ((prop (get-text-property from 'invisible))) 3543 (cond ((let ((prop (get-text-property from 'invisible)))
2687 ;; Decide whether this invisible property 3544 ;; Decide whether this invisible property
2688 ;; really makes the text invisible. 3545 ;; really makes the text invisible.
2689 (if (eq buffer-invisibility-spec t) 3546 (if (eq buffer-invisibility-spec t)
2690 (not (null prop)) 3547 (not (null prop))
2691 (or (memq prop buffer-invisibility-spec) 3548 (or (memq prop buffer-invisibility-spec)
2692 (assq prop buffer-invisibility-spec)))) 3549 (assq prop buffer-invisibility-spec))))
2693 nil) 3550 nil)
2694 ((get-text-property from 'face)) 3551 ((get-text-property from 'face))
2695 (t 'default))) 3552 (t 'default)))
2696 (let ((overlays (overlays-at from)) 3553 (let ((overlays (overlays-at from))
2697 (face-priority -1)) ; text-property 3554 (face-priority -1)) ; text-property
2698 (while overlays 3555 (while overlays
2699 (let* ((overlay (car overlays)) 3556 (let* ((overlay (car overlays))
2700 (overlay-face (overlay-get overlay 'face)) 3557 (overlay-face (overlay-get overlay 'face))
2701 (overlay-invisible (overlay-get overlay 'invisible)) 3558 (overlay-invisible (overlay-get overlay 'invisible))
2702 (overlay-priority (or (overlay-get overlay 3559 (overlay-priority (or (overlay-get overlay
2703 'priority) 3560 'priority)
2704 0))) 3561 0)))
2705 (if (and (or overlay-invisible overlay-face) 3562 (if (and (or overlay-invisible overlay-face)
2706 (> overlay-priority face-priority)) 3563 (> overlay-priority face-priority))
2707 (setq face (cond ((if (eq buffer-invisibility-spec t) 3564 (setq face (cond ((if (eq buffer-invisibility-spec t)
2708 (not (null overlay-invisible)) 3565 (not (null overlay-invisible))
2709 (or (memq overlay-invisible buffer-invisibility-spec) 3566 (or (memq overlay-invisible
2710 (assq overlay-invisible buffer-invisibility-spec))) 3567 buffer-invisibility-spec)
2711 nil) 3568 (assq overlay-invisible
2712 ((and face overlay-face))) 3569 buffer-invisibility-spec)))
2713 face-priority overlay-priority))) 3570 nil)
2714 (setq overlays (cdr overlays)))) 3571 ((and face overlay-face)))
2715 ;; Plot up to this record. 3572 face-priority overlay-priority)))
2716 (ps-plot-with-face from position face) 3573 (setq overlays (cdr overlays))))
2717 (setq from position))))) 3574 ;; Plot up to this record.
2718 (ps-plot-with-face from to face)))) 3575 (ps-plot-with-face from position face)
3576 (setq from position)))))
3577 (ps-plot-with-face from to face))))
2719 3578
2720(defun ps-generate-postscript (from to) 3579(defun ps-generate-postscript (from to)
2721 (ps-plot-region from to 0 nil)) 3580 (ps-plot-region from to 0 nil))
2722 3581
2723(defun ps-generate (buffer from to genfunc) 3582(defun ps-generate (buffer from to genfunc)
2724 (let ((from (min to from)) 3583 (save-excursion
2725 (to (max to from)) 3584 (let ((from (min to from))
2726 ;; This avoids trouble if chars with read-only properties 3585 (to (max to from))
2727 ;; are copied into ps-spool-buffer. 3586 ;; This avoids trouble if chars with read-only properties
2728 (inhibit-read-only t)) 3587 ;; are copied into ps-spool-buffer.
2729 (save-restriction 3588 (inhibit-read-only t))
2730 (narrow-to-region from to) 3589 (save-restriction
2731 (if ps-razzle-dazzle 3590 (narrow-to-region from to)
2732 (message "Formatting...%3d%%" (setq ps-razchunk 0))) 3591 (if ps-razzle-dazzle
2733 (set-buffer buffer) 3592 (message "Formatting...%3d%%" (setq ps-razchunk 0)))
2734 (setq ps-source-buffer buffer) 3593 (set-buffer buffer)
2735 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name)) 3594 (setq ps-source-buffer buffer)
2736 (ps-init-output-queue) 3595 (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
2737 (let (safe-marker completed-safely needs-begin-file) 3596 (ps-init-output-queue)
2738 (unwind-protect 3597 (let (safe-marker completed-safely needs-begin-file)
2739 (progn 3598 (unwind-protect
2740 (set-buffer ps-spool-buffer)
2741
2742 ;; Get a marker and make it point to the current end of the
2743 ;; buffer, If an error occurs, we'll delete everything from
2744 ;; the end of this marker onwards.
2745 (setq safe-marker (make-marker))
2746 (set-marker safe-marker (point-max))
2747
2748 (goto-char (point-min))
2749 (if (looking-at (regexp-quote "%!PS-Adobe-1.0"))
2750 nil
2751 (setq needs-begin-file t))
2752 (save-excursion
2753 (set-buffer ps-source-buffer)
2754 (if needs-begin-file (ps-begin-file))
2755 (ps-begin-job)
2756 (ps-begin-page))
2757 (set-buffer ps-source-buffer)
2758 (funcall genfunc from to)
2759 (ps-end-page)
2760
2761 (if (and ps-spool-duplex
2762 (= (mod ps-page-count 2) 1))
2763 (ps-dummy-page))
2764 (ps-flush-output)
2765
2766 ;; Back to the PS output buffer to set the page count
2767 (set-buffer ps-spool-buffer)
2768 (goto-char (point-max))
2769 (while (re-search-backward "^/PageCount 0 def$" nil t)
2770 (replace-match (format "/PageCount %d def" ps-page-count) t))
2771
2772 ;; Setting this variable tells the unwind form that the
2773 ;; the postscript was generated without error.
2774 (setq completed-safely t))
2775
2776 ;; Unwind form: If some bad mojo occurred while generating
2777 ;; postscript, delete all the postscript that was generated.
2778 ;; This protects the previously spooled files from getting
2779 ;; corrupted.
2780 (if (and (markerp safe-marker) (not completed-safely))
2781 (progn 3599 (progn
2782 (set-buffer ps-spool-buffer) 3600 (set-buffer ps-spool-buffer)
2783 (delete-region (marker-position safe-marker) (point-max))))))
2784 3601
2785 (if ps-razzle-dazzle 3602 ;; Get a marker and make it point to the current end of the
2786 (message "Formatting...done"))))) 3603 ;; buffer, If an error occurs, we'll delete everything from
3604 ;; the end of this marker onwards.
3605 (setq safe-marker (make-marker))
3606 (set-marker safe-marker (point-max))
3607
3608 (goto-char (point-min))
3609 (if (looking-at (regexp-quote ps-adobe-tag))
3610 nil
3611 (setq needs-begin-file t))
3612 (save-excursion
3613 (set-buffer ps-source-buffer)
3614 (if needs-begin-file (ps-begin-file))
3615 (ps-begin-job)
3616 (ps-begin-page))
3617 (set-buffer ps-source-buffer)
3618 (funcall genfunc from to)
3619 (ps-end-page)
3620
3621 (if (and ps-spool-duplex
3622 (= (mod ps-page-count 2) 1))
3623 (ps-dummy-page))
3624 (ps-flush-output)
3625
3626 ;; Back to the PS output buffer to set the page count
3627 (set-buffer ps-spool-buffer)
3628 (goto-char (point-max))
3629 (while (re-search-backward "^/PageCount 0 def$" nil t)
3630 (replace-match (format "/PageCount %d def" ps-page-count) t))
3631
3632 ;; Setting this variable tells the unwind form that the
3633 ;; the postscript was generated without error.
3634 (setq completed-safely t))
3635
3636 ;; Unwind form: If some bad mojo occurred while generating
3637 ;; postscript, delete all the postscript that was generated.
3638 ;; This protects the previously spooled files from getting
3639 ;; corrupted.
3640 (if (and (markerp safe-marker) (not completed-safely))
3641 (progn
3642 (set-buffer ps-spool-buffer)
3643 (delete-region (marker-position safe-marker) (point-max))))))
3644
3645 (if ps-razzle-dazzle
3646 (message "Formatting...done"))))))
2787 3647
2788(defun ps-do-despool (filename) 3648(defun ps-do-despool (filename)
2789 (if (or (not (boundp 'ps-spool-buffer)) 3649 (if (or (not (boundp 'ps-spool-buffer))
@@ -2805,8 +3665,10 @@ EndDSCPage\n"))
2805 (message "Printing...")) 3665 (message "Printing..."))
2806 (save-excursion 3666 (save-excursion
2807 (set-buffer ps-spool-buffer) 3667 (set-buffer ps-spool-buffer)
2808 (if (and (eq system-type 'ms-dos) (stringp dos-ps-printer)) 3668 (if (and (eq system-type 'ms-dos)
2809 (write-region (point-min) (point-max) dos-ps-printer t 0) 3669 (stringp (symbol-value 'dos-ps-printer)))
3670 (write-region (point-min) (point-max)
3671 (symbol-value 'dos-ps-printer) t 0)
2810 (let ((binary-process-input t)) ; for MS-DOS 3672 (let ((binary-process-input t)) ; for MS-DOS
2811 (apply 'call-process-region 3673 (apply 'call-process-region
2812 (point-min) (point-max) ps-lpr-command nil 3674 (point-min) (point-max) ps-lpr-command nil
@@ -2838,23 +3700,21 @@ EndDSCPage\n"))
2838;;; Sample Setup Code: 3700;;; Sample Setup Code:
2839 3701
2840;; This stuff is for anybody that's brave enough to look this far, 3702;; This stuff is for anybody that's brave enough to look this far,
2841;; and able to figure out how to use it. It isn't really part of ps- 3703;; and able to figure out how to use it. It isn't really part of
2842;; print, but I'll leave it here in hopes it might be useful: 3704;; ps-print, but I'll leave it here in hopes it might be useful:
2843 3705
2844;; WARNING!!! The following code is *sample* code only. Don't use it 3706;; WARNING!!! The following code is *sample* code only. Don't use it
2845;; unless you understand what it does! 3707;; unless you understand what it does!
2846 3708
2847(defmacro ps-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs) 3709(defmacro ps-prsc ()
2848 [f22] ''f22)) 3710 `(if (eq ps-print-emacs-type 'emacs) [f22] 'f22))
2849(defmacro ps-c-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs) 3711(defmacro ps-c-prsc ()
2850 [C-f22] 3712 `(if (eq ps-print-emacs-type 'emacs) [C-f22] '(control f22)))
2851 ''(control f22))) 3713(defmacro ps-s-prsc ()
2852(defmacro ps-s-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs) 3714 `(if (eq ps-print-emacs-type 'emacs) [S-f22] '(shift f22)))
2853 [S-f22]
2854 ''(shift f22)))
2855 3715
2856;; Look in an article or mail message for the Subject: line. To be 3716;; Look in an article or mail message for the Subject: line. To be
2857;; placed in ps-left-headers. 3717;; placed in `ps-left-headers'.
2858(defun ps-article-subject () 3718(defun ps-article-subject ()
2859 (save-excursion 3719 (save-excursion
2860 (goto-char (point-min)) 3720 (goto-char (point-min))
@@ -2864,12 +3724,13 @@ EndDSCPage\n"))
2864 3724
2865;; Look in an article or mail message for the From: line. Sorta-kinda 3725;; Look in an article or mail message for the From: line. Sorta-kinda
2866;; understands RFC-822 addresses and can pull the real name out where 3726;; understands RFC-822 addresses and can pull the real name out where
2867;; it's provided. To be placed in ps-left-headers. 3727;; it's provided. To be placed in `ps-left-headers'.
2868(defun ps-article-author () 3728(defun ps-article-author ()
2869 (save-excursion 3729 (save-excursion
2870 (goto-char (point-min)) 3730 (goto-char (point-min))
2871 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t) 3731 (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
2872 (let ((fromstring (buffer-substring-no-properties (match-beginning 1) (match-end 1)))) 3732 (let ((fromstring (buffer-substring-no-properties (match-beginning 1)
3733 (match-end 1))))
2873 (cond 3734 (cond
2874 3735
2875 ;; Try first to match addresses that look like 3736 ;; Try first to match addresses that look like
@@ -2886,12 +3747,12 @@ EndDSCPage\n"))
2886 (t fromstring))) 3747 (t fromstring)))
2887 "From ???"))) 3748 "From ???")))
2888 3749
2889;; A hook to bind to gnus-Article-prepare-hook. This will set the ps- 3750;; A hook to bind to gnus-Article-prepare-hook. This will set the
2890;; left-headers specially for gnus articles. Unfortunately, gnus- 3751;; `ps-left-headers' specially for gnus articles. Unfortunately,
2891;; article-mode-hook is called only once, the first time the *Article* 3752;; `gnus-article-mode-hook' is called only once, the first time the *Article*
2892;; buffer enters that mode, so it would only work for the first time 3753;; buffer enters that mode, so it would only work for the first time
2893;; we ran gnus. The second time, this hook wouldn't get set up. The 3754;; we ran gnus. The second time, this hook wouldn't get set up. The
2894;; only alternative is gnus-article-prepare-hook. 3755;; only alternative is `gnus-article-prepare-hook'.
2895(defun ps-gnus-article-prepare-hook () 3756(defun ps-gnus-article-prepare-hook ()
2896 (setq ps-header-lines 3) 3757 (setq ps-header-lines 3)
2897 (setq ps-left-header 3758 (setq ps-left-header
@@ -2899,8 +3760,8 @@ EndDSCPage\n"))
2899 ;; author, and the newsgroup it was in. 3760 ;; author, and the newsgroup it was in.
2900 (list 'ps-article-subject 'ps-article-author 'gnus-newsgroup-name))) 3761 (list 'ps-article-subject 'ps-article-author 'gnus-newsgroup-name)))
2901 3762
2902;; A hook to bind to vm-mode-hook to locally bind prsc and set the ps- 3763;; A hook to bind to vm-mode-hook to locally bind prsc and set the
2903;; left-headers specially for mail messages. This header setup would 3764;; ps-left-headers specially for mail messages. This header setup would
2904;; also work, I think, for RMAIL. 3765;; also work, I think, for RMAIL.
2905(defun ps-vm-mode-hook () 3766(defun ps-vm-mode-hook ()
2906 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary) 3767 (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
@@ -2915,14 +3776,18 @@ EndDSCPage\n"))
2915;; article subjects shows up at the printer. This function, bound to 3776;; article subjects shows up at the printer. This function, bound to
2916;; prsc for the gnus *Summary* buffer means I don't have to switch 3777;; prsc for the gnus *Summary* buffer means I don't have to switch
2917;; buffers first. 3778;; buffers first.
3779;; sb: Updated for Gnus 5.
2918(defun ps-gnus-print-article-from-summary () 3780(defun ps-gnus-print-article-from-summary ()
2919 (interactive) 3781 (interactive)
2920 (if (get-buffer "*Article*") 3782 (let ((ps-buf (or (and (boundp 'gnus-article-buffer)
2921 (save-excursion 3783 (symbol-value 'gnus-article-buffer))
2922 (set-buffer "*Article*") 3784 "*Article*")))
2923 (ps-spool-buffer-with-faces)))) 3785 (if (get-buffer ps-buf)
3786 (save-excursion
3787 (set-buffer ps-buf)
3788 (ps-spool-buffer-with-faces)))))
2924 3789
2925;; See ps-gnus-print-article-from-summary. This function does the 3790;; See `ps-gnus-print-article-from-summary'. This function does the
2926;; same thing for vm. 3791;; same thing for vm.
2927(defun ps-vm-print-message-from-summary () 3792(defun ps-vm-print-message-from-summary ()
2928 (interactive) 3793 (interactive)
@@ -2931,13 +3796,13 @@ EndDSCPage\n"))
2931 (set-buffer (symbol-value 'vm-mail-buffer)) 3796 (set-buffer (symbol-value 'vm-mail-buffer))
2932 (ps-spool-buffer-with-faces)))) 3797 (ps-spool-buffer-with-faces))))
2933 3798
2934;; A hook to bind to bind to gnus-summary-setup-buffer to locally bind 3799;; A hook to bind to bind to `gnus-summary-setup-buffer' to locally bind
2935;; prsc. 3800;; prsc.
2936(defun ps-gnus-summary-setup () 3801(defun ps-gnus-summary-setup ()
2937 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary)) 3802 (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
2938 3803
2939;; Look in an article or mail message for the Subject: line. To be 3804;; Look in an article or mail message for the Subject: line. To be
2940;; placed in ps-left-headers. 3805;; placed in `ps-left-headers'.
2941(defun ps-info-file () 3806(defun ps-info-file ()
2942 (save-excursion 3807 (save-excursion
2943 (goto-char (point-min)) 3808 (goto-char (point-min))
@@ -2946,7 +3811,7 @@ EndDSCPage\n"))
2946 "File ???"))) 3811 "File ???")))
2947 3812
2948;; Look in an article or mail message for the Subject: line. To be 3813;; Look in an article or mail message for the Subject: line. To be
2949;; placed in ps-left-headers. 3814;; placed in `ps-left-headers'.
2950(defun ps-info-node () 3815(defun ps-info-node ()
2951 (save-excursion 3816 (save-excursion
2952 (goto-char (point-min)) 3817 (goto-char (point-min))
@@ -2961,8 +3826,8 @@ EndDSCPage\n"))
2961 3826
2962;; WARNING! The following function is a *sample* only, and is *not* 3827;; WARNING! The following function is a *sample* only, and is *not*
2963;; meant to be used as a whole unless you understand what the effects 3828;; meant to be used as a whole unless you understand what the effects
2964;; will be! (In fact, this is a copy of Jim's setup for ps-print -- I'd 3829;; will be! (In fact, this is a copy of Jim's setup for ps-print --
2965;; be very surprised if it was useful to *anybody*, without 3830;; I'd be very surprised if it was useful to *anybody*, without
2966;; modification.) 3831;; modification.)
2967 3832
2968(defun ps-jts-ps-setup () 3833(defun ps-jts-ps-setup ()
@@ -2987,12 +3852,12 @@ EndDSCPage\n"))
2987;; without modification.) 3852;; without modification.)
2988 3853
2989(defun ps-jack-setup () 3854(defun ps-jack-setup ()
2990 (setq ps-print-color-p 'nil 3855 (setq ps-print-color-p nil
2991 ps-lpr-command "lpr" 3856 ps-lpr-command "lpr"
2992 ps-lpr-switches (list) 3857 ps-lpr-switches (list)
2993 3858
2994 ps-paper-type 'a4 3859 ps-paper-type 'a4
2995 ps-landscape-mode 't 3860 ps-landscape-mode t
2996 ps-number-of-columns 2 3861 ps-number-of-columns 2
2997 3862
2998 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm 3863 ps-left-margin (/ (* 72 1.0) 2.54) ; 1.0 cm