annotate lisp/image.el @ 25999:3dc900e05402

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Tue, 12 Oct 1999 21:12:16 +0000
parents 6ae50308e8a3
children 774b2504710b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; image.el --- image API
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
25857
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
3 ;; Copyright (C) 1998, 1999 Free Software Foundation, Inc.
25309
6842eb73559c Add Keywords.
Dave Love <fx@gnu.org>
parents: 25003
diff changeset
4 ;; Keywords: multimedia
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; any later version.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Code:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 (defconst image-type-regexps
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 '(("^/\\*.*XPM.\\*/" . xpm)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ("^P[1-6]" . pbm)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ("^GIF8" . gif)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ("JFIF" . jpeg)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ("^\211PNG\r\n" . png)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ("^#define" . xbm)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ("^\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ("^%!PS" . ghostscript))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 When the first bytes of an image file match REGEXP, it is assumed to
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 be of image type IMAGE-TYPE.")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 (defun image-type-from-file-header (file)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 "Determine the type of image file FILE from its first few bytes.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 Value is a symbol specifying the image type, or nil if type cannot
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 be determined."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (unless (file-name-directory file)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (setq file (concat data-directory file)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 (setq file (expand-file-name file))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 (let ((header (with-temp-buffer
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 (insert-file-contents-literally file nil 0 256)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (buffer-string)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (types image-type-regexps)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 type)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 (while (and types (null type))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 (let ((regexp (car (car types)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (image-type (cdr (car types))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (when (string-match regexp header)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (setq type image-type))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (setq types (cdr types))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 type))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (defun image-type-available-p (type)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 "Value is non-nil if image type TYPE is available.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 Image types are symbols like `xbm' or `jpeg'."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (not (null (memq type image-types))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 (defun create-image (file &optional type &rest props)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 "Create an image which will be loaded from FILE.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 Optional TYPE is a symbol describing the image type. If TYPE is omitted
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 or nil, try to determine the image file type from its first few bytes.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 If that doesn't work, use FILE's extension.as image type.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 Optional PROPS are additional image attributes to assign to the image,
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 like, e.g. `:heuristic-mask t'.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 Value is the image created, or nil if images of type TYPE are not supported."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (unless (stringp file)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (error "Invalid image file name %s" file))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 (unless (or type
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (setq type (image-type-from-file-header file)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 (let ((extension (file-name-extension file)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 (unless extension
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (error "Cannot determine image type"))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (setq type (intern extension))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (unless (symbolp type)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (error "Invalid image type %s" type))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (when (image-type-available-p type)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (append (list 'image :type type :file file) props)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;;;###autoload
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
94 (defun put-image (image pos string &optional area)
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
95 "Put image IMAGE in front of POS in the current buffer.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 IMAGE must be an image created with `create-image' or `defimage'.
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
97 IMAGE is displayed by putting an overlay into the current buffer with a
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
98 `before-string' STRING that has a `display' property whose value is the
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
99 image.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 POS may be an integer or marker.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 AREA is where to display the image. AREA nil or omitted means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 display it in the text area, a value of `left-margin' means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 display it in the left marginal area, a value of `right-margin'
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
104 means display it in the right marginal area."
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
105 (let ((buffer (current-buffer)))
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
106 (unless (eq (car image) 'image)
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
107 (error "Not an image: %s" image))
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
108 (unless (or (null area) (memq area '(left-margin right-margin)))
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
109 (error "Invalid area %s" area))
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
110 (setq string (copy-sequence string))
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
111 (let ((overlay (make-overlay pos pos buffer))
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
112 (prop (if (null area) image (list (list 'margin area) image))))
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
113 (put-text-property 0 (length string) 'display prop string)
25617
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
114 (overlay-put overlay 'put-image t)
697b28471784 (put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents: 25309
diff changeset
115 (overlay-put overlay 'before-string string))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 ;;;###autoload
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
119 (defun insert-image (image string &optional area)
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 "Insert IMAGE into current buffer at point.
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
121 IMAGE is displayed by inserting STRING into the current buffer
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
122 with a `display' property whose value is the image.
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 AREA is where to display the image. AREA nil or omitted means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 display it in the text area, a value of `left-margin' means
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 display it in the left marginal area, a value of `right-margin'
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
126 means display it in the right marginal area."
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (unless (eq (car image) 'image)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (error "Not an image: %s" image))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (unless (or (null area) (memq area '(left-margin right-margin)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (error "Invalid area %s" area))
25816
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
131 (when area
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
132 (setq image (list (list 'margin area) image)))
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
133 (let ((start (point)))
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
134 (insert string)
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
135 (add-text-properties start (point)
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
136 (list 'display image
2d53a03a3baa (put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents: 25617
diff changeset
137 'rear-nonsticky (list 'display)))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (defun remove-images (start end &optional buffer)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 "Remove images between START and END in BUFFER.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 Remove only images that were put in BUFFER with calls to `put-image'.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 BUFFER nil or omitted means use the current buffer."
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (unless buffer
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (setq buffer (current-buffer)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (let ((overlays (overlays-in start end)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (while overlays
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (let ((overlay (car overlays)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (when (overlay-get overlay 'put-image)
25857
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
151 (delete-overlay overlay)))
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
152 (setq overlays (cdr overlays)))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 ;;;###autoload
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (defmacro defimage (symbol specs &optional doc)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 "Define SYMBOL as an image.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 SPECS is a list of image specifications. DOC is an optional
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 documentation string.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 Each image specification in SPECS is a property list. The contents of
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 a specification are image type dependent. All specifications must at
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 least contain the properties `:type TYPE' and `:file FILE', where TYPE
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 is a symbol specifying the image type, e.g. `xbm', and FILE is the
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 file to load the image from. The first image specification whose TYPE
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 is supported, and FILE exists, is used to define SYMBOL.
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 Example:
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (defimage test-image ((:type xpm :file \"~/test1.xpm\")
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (:type xbm :file \"~/test1.xbm\")))"
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (let (image)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (while (and specs (null image))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (let* ((spec (car specs))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (type (plist-get spec :type))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (file (plist-get spec :file)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (when (and (image-type-available-p type) (stringp file))
25857
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
179 (setq file (expand-file-name file data-directory))
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
180 (when (file-readable-p file)
fdc2bd91cf63 (defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents: 25816
diff changeset
181 (setq image (cons 'image (plist-put spec :file file)))))
25003
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (setq specs (cdr specs))))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 `(defvar ,symbol ',image ,doc)))
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (provide 'image)
bb68fe3c72f8 New file.
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187
25872
6ae50308e8a3 Fix footer comment.
Dave Love <fx@gnu.org>
parents: 25857
diff changeset
188 ;;; image.el ends here