annotate lisp/w3/w3-print.el @ 0:376386a54a3c r19-14

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