aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ps-print.el140
1 files changed, 93 insertions, 47 deletions
diff --git a/lisp/ps-print.el b/lisp/ps-print.el
index cb2ab1d686d..73212f901fe 100644
--- a/lisp/ps-print.el
+++ b/lisp/ps-print.el
@@ -7,11 +7,11 @@
7;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br> 7;; Author: Vinicius Jose Latorre <vinicius@cpqd.com.br>
8;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br> 8;; Maintainer: Vinicius Jose Latorre <vinicius@cpqd.com.br>
9;; Keywords: print, PostScript 9;; Keywords: print, PostScript
10;; Time-stamp: <98/03/06 11:14:08 vinicius> 10;; Time-stamp: <98/05/05 12:36:30 vinicius>
11;; Version: 3.06 11;; Version: 3.06.1
12 12
13(defconst ps-print-version "3.06" 13(defconst ps-print-version "3.06.1"
14 "ps-print.el, v 3.06 <98/03/06 vinicius> 14 "ps-print.el, v 3.06.1 <98/05/05 vinicius>
15 15
16Vinicius's last change version -- this file may have been edited as part of 16Vinicius's last change version -- this file may have been edited as part of
17Emacs without changes to the version number. When reporting bugs, 17Emacs without changes to the version number. When reporting bugs,
@@ -371,17 +371,26 @@ Please send all bug fixes and enhancements to
371;; 371;;
372;; The variable `ps-print-control-characters' specifies whether you want to see 372;; The variable `ps-print-control-characters' specifies whether you want to see
373;; a printable form for control and 8-bit characters, that is, instead of 373;; a printable form for control and 8-bit characters, that is, instead of
374;; sending, for example, a ^D (\005) to printer, it is sent the string "^D". 374;; sending, for example, a ^D (\004) to printer, it is sent the string "^D".
375;; 375;;
376;; Valid values for `ps-print-control-characters' are: 376;; Valid values for `ps-print-control-characters' are:
377;; 377;;
378;; '8-bit printable form for control and 8-bit characters 378;; '8-bit This is the value to use when you want an ascii encoding of
379;; (characters from \000 to \037 and \177 to \377). 379;; any control or non-ascii character. Control characters are
380;; 'control-8-bit printable form for control and *control* 8-bit characters 380;; encoded as "^D", and non-ascii characters have an
381;; (characters from \000 to \037 and \177 to \237). 381;; octal encoding.
382;; 'control printable form for control character 382;;
383;; (characters from \000 to \037 and \177). 383;; 'control-8-bit This is the value to use when you want an ascii encoding of
384;; nil raw character (no printable form). 384;; any control character, whether it is 7 or 8-bit.
385;; European 8-bits accented characters are printed according
386;; the current font.
387;;
388;; 'control Only ascii control characters have an ascii encoding.
389;; European 8-bits accented characters are printed according
390;; the current font.
391;;
392;; nil No ascii encoding. Any character is printed according the
393;; current font.
385;; 394;;
386;; Any other value is treated as nil. 395;; Any other value is treated as nil.
387;; 396;;
@@ -811,15 +820,22 @@ Please send all bug fixes and enhancements to
811;; Acknowledgements 820;; Acknowledgements
812;; ---------------- 821;; ----------------
813;; 822;;
823;; Thanks to Roland Ducournau <ducour@lirmm.fr> for
824;; `ps-print-control-characters' variable documentation.
825;;
814;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better 826;; Thanks to Marcus G Daniels <marcus@cathcart.sysc.pdx.edu> for a better
815;; database font management. 827;; database font management.
816;; 828;;
817;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one 829;; Thanks to Martin Boyer <gamin@videotron.ca> for some ideas on putting one
818;; header per page over the columns. 830;; header per page over the columns and correct line numbers when printing a
831;; region.
819;; 832;;
820;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at 833;; Thanks to Steven L Baur <steve@miranova.com> for dynamic evaluation at
821;; print time of `ps-lpr-switches'. 834;; print time of `ps-lpr-switches'.
822;; 835;;
836;; Thanks to Kevin Rodgers <kevinr@ihs.com> for handling control characters
837;; (his code was severely modified, but the main idea was kept).
838;;
823;; Thanks to some suggestions on: 839;; Thanks to some suggestions on:
824;; * Face color map: Marco Melgazzi <marco@techie.com> 840;; * Face color map: Marco Melgazzi <marco@techie.com>
825;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx> 841;; * XEmacs compatibility: William J. Henney <will@astrosmo.unam.mx>
@@ -856,9 +872,6 @@ Please send all bug fixes and enhancements to
856 872
857;;; Code: 873;;; Code:
858 874
859(eval-when-compile
860 (require 'cl))
861
862(unless (featurep 'lisp-float-type) 875(unless (featurep 'lisp-float-type)
863 (error "`ps-print' requires floating point support")) 876 (error "`ps-print' requires floating point support"))
864 877
@@ -981,14 +994,28 @@ example `letter', `legal' or `a4'."
981 994
982(defcustom ps-print-control-characters 'control-8-bit 995(defcustom ps-print-control-characters 'control-8-bit
983 "*Specifies the printable form for control and 8-bit characters. 996 "*Specifies the printable form for control and 8-bit characters.
997That is, instead of sending, for example, a ^D (\004) to printer,
998it is sent the string \"^D\".
999
984Valid values are: 1000Valid values are:
985 '8-bit printable form for control and 8-bit characters 1001
986 (characters from \000 to \037 and \177 to \377). 1002 '8-bit This is the value to use when you want an ascii encoding of
987 'control-8-bit printable form for control and *control* 8-bit characters 1003 any control or non-ascii character. Control characters are
988 (characters from \000 to \037 and \177 to \237). 1004 encoded as \"^D\", and non-ascii characters have an
989 'control printable form for control character 1005 octal encoding.
990 (characters from \000 to \037 and \177). 1006
991 nil raw character (no printable form). 1007 'control-8-bit This is the value to use when you want an ascii encoding of
1008 any control character, whether it is 7 or 8-bit.
1009 European 8-bits accented characters are printed according
1010 the current font.
1011
1012 'control Only ascii control characters have an ascii encoding.
1013 European 8-bits accented characters are printed according
1014 the current font.
1015
1016 nil No ascii encoding. Any character is printed according the
1017 current font.
1018
992Any other value is treated as nil." 1019Any other value is treated as nil."
993 :type '(choice (const 8-bit) (const control-8-bit) 1020 :type '(choice (const 8-bit) (const control-8-bit)
994 (const control) (const nil)) 1021 (const control) (const nil))
@@ -2488,7 +2515,7 @@ See `ps-extend-face' for documentation."
2488(defun ps-extend-face (face-extension &optional merge-p) 2515(defun ps-extend-face (face-extension &optional merge-p)
2489 "Extend face in `ps-print-face-extension-alist'. 2516 "Extend face in `ps-print-face-extension-alist'.
2490 2517
2491If optional MERGE-P is non-nil, extensions in FACE-EXTENSION-LIST are merged 2518If optional MERGE-P is non-nil, extensions in FACE-EXTENSION list are merged
2492with face extensions in `ps-print-face-extension-alist'; otherwise, overrides. 2519with face extensions in `ps-print-face-extension-alist'; otherwise, overrides.
2493 2520
2494The elements of FACE-EXTENSION list have the form: 2521The elements of FACE-EXTENSION list have the form:
@@ -2554,7 +2581,9 @@ If EXTENSION is any other symbol, it is ignored."
2554 (boundp 'font-lock-face-attributes) 2581 (boundp 'font-lock-face-attributes)
2555 (let ((face-attributes font-lock-face-attributes)) 2582 (let ((face-attributes font-lock-face-attributes))
2556 (while face-attributes 2583 (while face-attributes
2557 (let* ((face-attribute (pop face-attributes)) 2584 (let* ((face-attribute
2585 (car (prog1 face-attributes
2586 (setq face-attributes (cdr face-attributes)))))
2558 (face (car face-attribute))) 2587 (face (car face-attribute)))
2559 ;; Rustle up a `defface' SPEC from a 2588 ;; Rustle up a `defface' SPEC from a
2560 ;; `font-lock-face-attributes' entry. 2589 ;; `font-lock-face-attributes' entry.
@@ -2645,15 +2674,15 @@ and to indicate in the header that the printout is of a partial file.")
2645 "Font family name for text of `font-type', when generating PostScript." 2674 "Font family name for text of `font-type', when generating PostScript."
2646 (let* ((font-list (ps-font-list font-sym)) 2675 (let* ((font-list (ps-font-list font-sym))
2647 (normal-font (cdr (assq 'normal font-list)))) 2676 (normal-font (cdr (assq 'normal font-list))))
2648 (loop for font in font-list do 2677 (while (and font-list (not (eq font-type (car (car font-list)))))
2649 (when (eq font-type (car font)) 2678 (setq font-list (cdr font-list)))
2650 (return (or (cdr font) normal-font)))))) 2679 (or (cdr (car font-list)) normal-font)))
2651 2680
2652(defun ps-fonts (font-sym) 2681(defun ps-fonts (font-sym)
2653 (loop for font in (ps-font-list font-sym) collect (cdr font))) 2682 (mapcar 'cdr (ps-font-list font-sym)))
2654 2683
2655(defun ps-font-number (font-sym font-type) 2684(defun ps-font-number (font-sym font-type)
2656 (or (position font-type (ps-font-list font-sym) :key 'car) 2685 (or (ps-position font-type (ps-font-list font-sym))
2657 0)) 2686 0))
2658 2687
2659(defsubst ps-line-height (font-sym) 2688(defsubst ps-line-height (font-sym)
@@ -2767,21 +2796,23 @@ using the current ps-print setup."
2767 (insert "\n") 2796 (insert "\n")
2768 (display-buffer buf 'not-this-window))) 2797 (display-buffer buf 'not-this-window)))
2769 2798
2799;; macros used in `ps-select-font'
2800(defmacro ps-lookup (key) `(cdr (assq ,key font-entry)))
2801(defmacro ps-size-scale (key) `(/ (* (ps-lookup ,key) font-size) size))
2802
2770(defun ps-select-font (font-family sym font-size title-font-size) 2803(defun ps-select-font (font-family sym font-size title-font-size)
2771 (let ((font-entry (cdr (assq font-family ps-font-info-database)))) 2804 (let ((font-entry (cdr (assq font-family ps-font-info-database))))
2772 (or font-entry 2805 (or font-entry
2773 (error "Don't have data to scale font %s. Known fonts families are %s" 2806 (error "Don't have data to scale font %s. Known fonts families are %s"
2774 font-family 2807 font-family
2775 (mapcar 'car ps-font-info-database))) 2808 (mapcar 'car ps-font-info-database)))
2776 (flet ((lookup (key) (cdr (assq key font-entry)))) 2809 (let ((size (ps-lookup 'size)))
2777 (let ((size (lookup 'size))) 2810 (put sym 'fonts (ps-lookup 'fonts))
2778 (put sym 'fonts (lookup 'fonts)) 2811 (put sym 'space-width (ps-size-scale 'space-width))
2779 (flet ((size-scale (key) (/ (* (lookup key) font-size) size))) 2812 (put sym 'avg-char-width (ps-size-scale 'avg-char-width))
2780 (put sym 'space-width (size-scale 'space-width)) 2813 (put sym 'line-height (ps-size-scale 'line-height))
2781 (put sym 'avg-char-width (size-scale 'avg-char-width)) 2814 (put sym 'title-line-height
2782 (put sym 'line-height (size-scale 'line-height)) 2815 (/ (* (ps-lookup 'line-height) title-font-size) size)))))
2783 (put sym 'title-line-height
2784 (/ (* (lookup 'line-height) title-font-size) size)))))))
2785 2816
2786(defun ps-get-page-dimensions () 2817(defun ps-get-page-dimensions ()
2787 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database))) 2818 (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
@@ -3154,6 +3185,19 @@ page-height == bm + print-height + tm - ho - hh
3154 (setq tail (cdr tail))) 3185 (setq tail (cdr tail)))
3155 (nreverse new))) 3186 (nreverse new)))
3156 3187
3188;; Find the first occurrence of ITEM in LIST.
3189;; Return the index of the matching item, or nil if not found.
3190;; Elements are compared with `eq'.
3191(defun ps-position (item list)
3192 (let ((tail list) (index 0) found)
3193 (while tail
3194 (if (setq found (eq (car tail) item))
3195 (setq tail nil)
3196 (setq index (1+ index)
3197 tail (cdr tail))))
3198 (and found index)))
3199
3200
3157(defun ps-begin-file () 3201(defun ps-begin-file ()
3158 (ps-get-page-dimensions) 3202 (ps-get-page-dimensions)
3159 (setq ps-showline-count (if ps-printing-region (car ps-printing-region) 1) 3203 (setq ps-showline-count (if ps-printing-region (car ps-printing-region) 1)
@@ -3247,13 +3291,15 @@ page-height == bm + print-height + tm - ho - hh
3247 (ps-output ps-print-prologue-2) 3291 (ps-output ps-print-prologue-2)
3248 3292
3249 ;; Text fonts 3293 ;; Text fonts
3250 (loop for font in (ps-font-list 'ps-font-for-text) 3294 (let ((font (ps-font-list 'ps-font-for-text))
3251 for i from 0 3295 (i 0))
3252 do 3296 (while font
3253 (ps-output (format "/f%d %s /%s DefFont\n" 3297 (ps-output (format "/f%d %s /%s DefFont\n"
3254 i 3298 i
3255 ps-font-size 3299 ps-font-size
3256 (ps-font 'ps-font-for-text (car font))))) 3300 (ps-font 'ps-font-for-text (car (car font)))))
3301 (setq font (cdr font)
3302 i (1+ i))))
3257 3303
3258 (ps-output "\nBeginDoc\n\n" 3304 (ps-output "\nBeginDoc\n\n"
3259 "%%EndPrologue\n")) 3305 "%%EndPrologue\n"))
@@ -3307,7 +3353,7 @@ page-height == bm + print-height + tm - ho - hh
3307(defun ps-header-page () 3353(defun ps-header-page ()
3308 (if (prog1 3354 (if (prog1
3309 (zerop (mod ps-page-count ps-number-of-columns)) 3355 (zerop (mod ps-page-count ps-number-of-columns))
3310 (incf ps-page-count)) 3356 (setq ps-page-count (1+ ps-page-count)))
3311 ;; Print only when a new real page begins. 3357 ;; Print only when a new real page begins.
3312 (let ((page-number (ps-page-number))) 3358 (let ((page-number (ps-page-number)))
3313 (ps-output (format "\n%%%%Page: %d %d\n" page-number page-number)) 3359 (ps-output (format "\n%%%%Page: %d %d\n" page-number page-number))