X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=tm-image.el;h=84c109b7e42133dd02a7e9a26957d7a0db2a2438;hb=04947254acc41d871e666080acaf7330d60d32e4;hp=47722487153fc3b64800647f71a09cea5a77ece2;hpb=1e934fd62b8a1ec9d52ee3498639cfaba648cd81;p=elisp%2Ftm.git diff --git a/tm-image.el b/tm-image.el index 4772248..84c109b 100644 --- a/tm-image.el +++ b/tm-image.el @@ -1,51 +1,64 @@ -;;; -;;; tm-image.el --- a tm-view content filter to display images in -;;; XEmacs or Mule buffers -;;; -;;; Copyright (C) 1995,1996 MORIOKA Tomohiko -;;; -;;; Author: MORIOKA Tomohiko -;;; Maintainer: MORIOKA Tomohiko -;;; Created: 1995/12/15 -;;; Version: -;;; $Id: tm-image.el,v 4.6 1996/02/13 17:56:43 morioka Exp $ -;;; -;;; Keywords: mail, news, MIME, multimedia, image, picture -;;; -;;; This file is part of tm (Tools for MIME). -;;; -;;; 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 This program. If not, write to the Free Software -;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -;;; +;;; tm-image.el --- tm-view filter to display images in XEmacs or MULE buffers + +;; Copyright (C) 1995,1996 MORIOKA Tomohiko +;; Copyright (C) 1996 Dan Rich + +;; Author: MORIOKA Tomohiko +;; Dan Rich +;; Maintainer: MORIOKA Tomohiko +;; Created: 1995/12/15 +;; Version: $Id: tm-image.el,v 7.14 1996/08/28 18:43:29 morioka Exp $ + +;; Keywords: mail, news, MIME, multimedia, image, picture, X-Face + +;; This file is part of tm (Tools for MIME). + +;; 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 this program; 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 bitmap -;;; extension package. It is available from -;;; ftp://etlport.etl.go.jp/pub/mule/contrib/bitmap.tar.gz -;;; +;; If you use this program with MULE, please install +;; etl8x16-bitmap.bdf font included in tl package. + ;;; Code: (require 'tm-view) -(cond ((string-match "XEmacs" emacs-version) - (require 'xpm) +(cond (running-xemacs (require 'annotations) (set-alist 'mime-viewer/content-filter-alist - "image/jpeg" (function mime-preview/filter-for-image)) + "image/jpeg" + (if (featurep 'jpeg) ; Use built-in suport if available + (function mime-preview/filter-for-inline-image) + (function mime-preview/filter-for-image) + )) + + (set-alist 'mime-viewer/content-filter-alist + "image/gif" + (if (featurep 'gif) ; Use built-in suport if available + (function mime-preview/filter-for-inline-image) + (function mime-preview/filter-for-image) + )) (set-alist 'mime-viewer/content-filter-alist - "image/gif" (function mime-preview/filter-for-image)) + "image/x-xpixmap" + (if (featurep 'xpm) ; Use built-in suport if available + (function mime-preview/filter-for-inline-image) + (function mime-preview/filter-for-image) + )) (set-alist 'mime-viewer/content-filter-alist "image/tiff" (function mime-preview/filter-for-image)) @@ -59,10 +72,17 @@ "image/x-mag" (function mime-preview/filter-for-image)) (defvar tm-image/inline-image-types - '("image/jpeg" "image/gif" "image/tiff" - "image/x-tiff" "image/x-pic" "image/x-mag" "image/x-xbm")) - - (defun bitmap-read-xbm (file) + (if (featurep 'gif) + (nconc + '("image/jpeg" "image/gif" "image/tiff" + "image/x-tiff" "image/x-pic" "image/x-mag" + "image/x-xbm" "image/x-xpixmap") + (if (featurep 'gif) + '("application/postscript") + ) + ))) + + (defun bitmap-insert-xbm-file (file) (let (gl) (while (progn (setq gl (make-glyph file)) @@ -72,21 +92,36 @@ (make-annotation gl (point) 'text) )) + (defvar mime-viewer/image-converter-alist + '(("image/jpeg" . jpeg) + ("image/gif" . gif) + ("image/x-png" . png) + ("image/x-xpixmap" . xpm) + )) + (defvar mime-preview/x-face-function - (function mime-preview/x-face-function-for-xemacs)) + (function mime-preview/x-face-function-use-highlight-headers)) + + (autoload 'highlight-headers "highlight-headers") + + (defun mime-preview/x-face-function-use-highlight-headers () + (highlight-headers (point-min) (re-search-forward "^$" nil t) t) + ) ) ((boundp 'MULE) - (require 'bitmap) + (require 'x-face-mule) (defvar tm-image/inline-image-types '("image/x-mag" "image/x-xbm")) (defvar mime-preview/x-face-function - (function mime-preview/x-face-function-for-mule)) + (function x-face-decode-message-header)) )) (defvar mime-viewer/shell-command "/bin/sh") (defvar mime-viewer/shell-arguments '("-c")) +(defvar mime-viewer/ps-to-gif-command "pstogif") + (defvar mime-viewer/graphic-converter-alist '(("image/jpeg" . "djpeg -color 256 < %s | ppmtoxpm > %s") ("image/gif" . "giftopnm < %s | ppmtoxpm > %s") @@ -96,92 +131,22 @@ ("image/x-mag" . "magtoppm < %s | ppmtoxpm > %s") )) + +;;; @ X-Face +;;; + (defvar mime-viewer/x-face-to-xbm-command (concat mime-viewer/x-face-to-pbm-command " | pbmtoxbm")) -(add-hook 'mime-viewer/content-header-filter-hook - mime-preview/x-face-function) - -(defun mime-preview/x-face-function-for-xemacs () - (save-restriction - (narrow-to-region (point-min) (re-search-forward "^$" nil t)) - (goto-char (point-min)) - (if (re-search-forward "^X-Face:[ \t]*" nil t) - (let ((beg (match-end 0)) - (end (rfc822/field-end)) - (xbm-file - (make-temp-name (expand-file-name "tmxf" mime/tmp-dir)) - )) - (call-process-region - beg end "sh" nil 0 nil - "-c" - (format "%s > %s" - mime-viewer/x-face-to-xbm-command - xbm-file)) - (while (not (file-exists-p xbm-file))) - (delete-region beg end) - (bitmap-read-xbm xbm-file) - (condition-case nil - (delete-file xbm-file) - (error nil)) - )))) - -(defun mime-preview/x-face-function-for-mule () - (save-restriction - (narrow-to-region (point-min) (re-search-forward "^$" nil t)) - (goto-char (point-min)) - (if (re-search-forward "^X-Face:[ \t]*" nil t) - (let ((p (match-beginning 0)) - (beg (match-end 0)) - (end (rfc822/field-end)) - (xbm-file - (concat - (make-temp-name (expand-file-name "tmxf" mime/tmp-dir)) - ".xbm") - )) - (if (< end (point-max)) - (setq end (1+ end)) - ) - (while (progn - (call-process-region - beg end "sh" nil 0 nil - "-c" - (format "%s > %s" - mime-viewer/x-face-to-xbm-command - xbm-file)) - (not (file-exists-p xbm-file)) - )) - (save-restriction - (narrow-to-region p end) - (delete-region p end) - (goto-char p) - (while (progn - (condition-case nil - (bitmap-read-xbm xbm-file) - (error nil)) - (kill-buffer - (some-element - (function - (lambda (buf) - (string-equal (buffer-file-name buf) xbm-file) - )) - (buffer-list))) - (= (point-min) (point-max)) - )) - (goto-char p) - (insert "X-Face: ") - (while (re-search-forward "^." nil t) - (goto-char (match-beginning 0)) - (insert " ") - )) - (condition-case nil - (delete-file xbm-file) - (error nil)) - )))) +(if mime-preview/x-face-function + (add-hook 'mime-viewer/content-header-filter-hook + mime-preview/x-face-function) + ) ;;; @ content filter for images ;;; +;; (for XEmacs 19.12 or later) (defun mime-preview/filter-for-image (ctype params encoding) (let* ((mode mime::preview/original-major-mode) @@ -195,7 +160,7 @@ (xbm-file (concat orig-file ".xbm")) gl annot) ;;(remove-text-properties beg end '(face nil)) - (mime/decode-region encoding beg end) + (mime-decode-region beg end encoding) (write-region (point-min)(point-max) orig-file) (delete-region (point-min)(point-max)) (message "Now translating, please wait...") @@ -230,10 +195,10 @@ (xbm-file (make-temp-name (expand-file-name "tm" mime/tmp-dir))) ) (remove-text-properties beg end '(face nil)) - (mime/decode-region encoding beg end) + (mime-decode-region beg end encoding) (write-region (point-min)(point-max) xbm-file) (delete-region (point-min)(point-max)) - (bitmap-read-xbm xbm-file) + (bitmap-insert-xbm-file xbm-file) (delete-file xbm-file) )) @@ -244,6 +209,67 @@ "image/x-xbm" (function mime-preview/filter-for-image/xbm)) +;;; @ content filter for support in-line image types +;;; +;; (for XEmacs 19.14 or later) + +(defun mime-preview/filter-for-inline-image (ctype params encoding) + (let* ((mode mime::preview/original-major-mode) + (m (assq mode mime-viewer/code-converter-alist)) + (charset (assoc "charset" params)) + (beg (point-min)) (end (point-max)) + ) + (remove-text-properties beg end '(face nil)) + (mime-decode-region beg end encoding) + (let ((data (buffer-string)) + (minor (assoc-value ctype mime-viewer/image-converter-alist)) + gl) + (delete-region (point-min)(point-max)) + (while (progn + (setq gl (make-glyph (vector minor :data data))) + (eq (image-instance-type (glyph-image-instance gl)) + 'text) + )) + (make-annotation gl (point) 'text) + ) + (insert "\n") + )) + + +;;; @ content filter for Postscript +;;; +;; (for XEmacs 19.14 or later) + +(defun mime-preview/filter-for-application/postscript (ctype params encoding) + (let* ((mode mime::preview/original-major-mode) + (m (assq mode mime-viewer/code-converter-alist)) + (beg (point-min)) (end (point-max)) + (file-base (make-temp-name (expand-file-name "tm" mime/tmp-dir))) + (ps-file (concat file-base ".ps")) + (gif-file (concat file-base ".gif")) + ) + (remove-text-properties beg end '(face nil)) + (mime-decode-region beg end encoding) + (write-region (point-min)(point-max) ps-file) + (delete-region (point-min)(point-max)) + (call-process mime-viewer/ps-to-gif-command nil nil nil ps-file) + (let (gl) + (while (progn + (setq gl (make-glyph (vector 'gif :file gif-file))) + (eq (image-instance-type (glyph-image-instance gl)) + 'text) + )) + (make-annotation gl (point) 'text) + ) + (delete-file ps-file) + (delete-file gif-file) + )) + +(set-alist 'mime-viewer/content-filter-alist + "application/postscript" + (function mime-preview/filter-for-application/postscript)) + + ;;; @ setting ;;;