1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
;;; mime-image.el --- mime-view filter to display images
;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
;; Copyright (C) 1996 Dan Rich
;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
;; Dan Rich <drich@morpheus.corp.sgi.com>
;; Maintainer: MORIOKA Tomohiko <morioka@jaist.ac.jp>
;; Created: 1995/12/15
;; Renamed: 1997/2/21 from tm-image.el
;; Keywords: image, picture, X-Face, MIME, multimedia, mail, news
;; This file is part of SEMI (Showy Emacs MIME Interfaces).
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU XEmacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; If you use this program with MULE, please install
;; etl8x16-bitmap.bdf font included in tl package.
;;; Code:
(require 'mime-view)
(require 'alist)
(cond ((featurep 'xemacs)
(require 'images)
(defun-maybe image-inline-p (format)
(or (memq format image-native-formats)
(find-if (function
(lambda (native)
(image-converter-chain format native)
))
image-native-formats)
))
(image-register-netpbm-utilities)
(image-register-converter 'pic 'ppm "pictoppm")
(image-register-converter 'mag 'ppm "magtoppm")
(defun bitmap-insert-xbm-file (file)
(let ((gl (make-glyph (list (cons 'x file))))
(e (make-extent (point) (point)))
)
(set-extent-end-glyph e gl)
))
;;
;; X-Face
;;
(autoload 'highlight-headers "highlight-headers")
(defun mime-preview-x-face-function-use-highlight-headers ()
(highlight-headers (point-min) (re-search-forward "^$" nil t) t)
)
(add-hook 'mime-display-header-hook
'mime-preview-x-face-function-use-highlight-headers)
)
((featurep 'mule)
;; for MULE 2.* or mule merged EMACS
(require 'x-face-mule)
(defvar image-native-formats '(xbm))
(defun-maybe image-inline-p (format)
(memq format image-native-formats)
)
(defun-maybe image-normalize (format data)
(and (eq format 'xbm)
(vector 'xbm ':data data)
))
;;
;; X-Face
;;
(if (exec-installed-p uncompface-program exec-path)
(add-hook 'mime-display-header-hook
'x-face-decode-message-header)
)
))
(or (fboundp 'image-invalid-glyph-p)
(defsubst image-invalid-glyph-p (glyph)
(or (null (aref glyph 0))
(null (aref glyph 2))
(equal (aref glyph 2) "")
))
)
(mapcar (function
(lambda (rule)
(let ((type (car rule))
(subtype (nth 1 rule))
(format (nth 2 rule)))
(if (image-inline-p format)
(ctree-set-calist-strictly
'mime-preview-condition
(list (cons 'type type)(cons 'subtype subtype)
'(body . visible)
(cons 'body-presentation-method #'mime-display-image)
(cons 'image-format format))
)))))
'((image jpeg jpeg)
(image gif gif)
(image tiff tiff)
(image x-tiff tiff)
(image xbm xbm)
(image x-xbm xbm)
(image x-xpixmap xpm)
(image x-pic pic)
(image x-mag mag)
(image png png)
))
;;; @ content filter for images
;;;
;; (for XEmacs 19.12 or later)
(defun mime-display-image (entity situation)
(message "Decoding image...")
(let ((gl (image-normalize (cdr (assq 'image-format situation))
(mime-entity-content entity))))
(cond ((image-invalid-glyph-p gl)
(setq gl nil)
(message "Invalid glyph!")
)
((eq (aref gl 0) 'xbm)
(let ((xbm-file
(make-temp-name
(expand-file-name "tm" temporary-file-directory))))
(with-temp-buffer
(insert (aref gl 2))
(write-region (point-min)(point-max) xbm-file)
)
(message "Decoding image...")
(bitmap-insert-xbm-file xbm-file)
(delete-file xbm-file)
)
(message "Decoding image... done")
)
(t
(setq gl (make-glyph gl))
(let ((e (make-extent (point) (point))))
(set-extent-end-glyph e gl)
)
(message "Decoding image... done")
))
)
(insert "\n")
)
;;; @ end
;;;
(provide 'mime-image)
;;; mime-image.el ends here
|