annotate lisp/w3/w3-print.el @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents ac2d302a0011
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1 ;;; w3-print.el --- Printing support for emacs-w3
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Author: wmperry
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
3 ;; Created: 1996/10/09 19:00:59
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
4 ;; Version: 1.5
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: faces, help, printing, hypermedia
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
8 ;;; Copyright (c) 1993 - 1996 by William M. Perry (wmperry@cs.indiana.edu)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
9 ;;; Copyright (c) 1996 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 2
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (defvar w3-use-ps-print nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 "*If non-nil, then printing will be done via the ps-print package by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 James C. Thompson <thompson@wg2.waii.com>.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defun w3-face-type (face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 "Return a list specifying what a face looks like. ie: '(bold italic)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (let ((font (or (face-font face) (face-font 'default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (retval nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (if (not (stringp font))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (setq font
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ((and (fboundp 'fontp) (not (fontp font))) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ((fboundp 'font-truename) (font-truename font))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ((fboundp 'font-name) (font-name font))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ((not font) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ((string-match "^-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-\\([^-]+\\)-" font)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (let ((wght (substring font (match-beginning 3) (match-end 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (slnt (substring font (match-beginning 4) (match-end 4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (if (string-match "bold" wght)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (setq retval (cons 'bold retval)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (if (or (string-match "i" slnt) (string-match "o" slnt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq retval (cons 'italic retval)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (if (and (fboundp 'face-underline-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (face-underline-p face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (setq retval (cons 'underline retval)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ((and (symbolp face) (string-match "bold" (symbol-name face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (setq retval '(bold)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ((and (symbolp face) (string-match "italic" (symbol-name face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (setq retval '(italic)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 retval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun w3-print-with-ps-print (&optional buffer function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Print a buffer using `ps-print-buffer-with-faces'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 This function wraps `ps-print-buffer-with-faces' so that the w3 faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 will be correctly listed in ps-bold-faces and ps-italic-faces"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (require 'ps-print)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (setq buffer (or buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 function (or function 'ps-print-buffer-with-faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (let ((ps-bold-faces ps-bold-faces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (ps-italic-faces ps-italic-faces)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
72 (inhibit-read-only t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (ps-underline-faces (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ((boundp 'ps-underline-faces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (symbol-value 'ps-underline-faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ((boundp 'ps-underlined-faces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (symbol-value 'ps-underlined-faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (ps-underlined-faces nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (ps-left-header '(ps-get-buffer-name url-view-url))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (faces (face-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (data nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (face nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (if (string< ps-print-version "1.6")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (while faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq face (car faces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 data (w3-face-type face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 faces (cdr faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if (and (memq 'bold data) (not (memq face ps-bold-faces)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (setq ps-bold-faces (cons face ps-bold-faces)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (and (memq 'italic data) (not (memq face ps-italic-faces)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq ps-italic-faces (cons face ps-italic-faces)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (if (and (memq 'underline data) (not (memq face ps-underline-faces)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (setq ps-underline-faces (cons face ps-underline-faces))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq ps-underlined-faces ps-underline-faces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (funcall function))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defun w3-print-this-url (&optional url format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "Print out the current document (in LaTeX format)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (if (not url) (setq url (url-view-url t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let* ((completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (format (or format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "Format: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 '(("HTML Source") ; The raw HTML code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ("Formatted Text") ; Plain ASCII rendition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ("PostScript") ; Pretty PostScript
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ("LaTeX'd") ; LaTeX it, then print
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ((equal "HTML Source" format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if w3-current-source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (let ((x w3-current-source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (set-buffer (get-buffer-create url-working-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (insert x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (url-retrieve url))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (lpr-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ((or (equal "Formatted Text" format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (equal "" format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (lpr-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ((equal "PostScript" format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (w3-print-with-ps-print (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ((equal "LaTeX'd" format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (w3-parse-tree-to-latex w3-current-parse url)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (write-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (expand-file-name "w3-tmp.latex"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 w3-temporary-directory) nil 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (shell-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 "cd %s ; latex w3-tmp.latex ; %s w3-tmp.dvi ; rm -f w3-tmp*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 w3-temporary-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 w3-print-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (kill-buffer "*Shell Command Output*")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defun w3-print-url-under-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "Print out the url under point (in LaTeX format)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (w3-print-this-url (w3-view-this-url t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (provide 'w3-print)