Mercurial > emacs
annotate lisp/image.el @ 28923:dcafe3c9cd6c
(sh-while-getopts) <sh>: Handle case that
user-specified option string is empty.
| author | Gerd Moellmann <gerd@gnu.org> |
|---|---|
| date | Mon, 15 May 2000 20:14:39 +0000 |
| parents | b4ea18c92e38 |
| children | 56c76b64f321 |
| rev | line source |
|---|---|
| 25003 | 1 ;;; image.el --- image API |
| 2 | |
|
27921
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. |
| 25309 | 4 ;; Keywords: multimedia |
| 25003 | 5 |
| 6 ;; This file is part of GNU Emacs. | |
| 7 | |
| 8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 9 ;; it under the terms of the GNU General Public License as published by | |
| 10 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 11 ;; any later version. | |
| 12 | |
| 13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 ;; GNU General Public License for more details. | |
| 17 | |
| 18 ;; You should have received a copy of the GNU General Public License | |
| 19 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
| 20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 21 ;; Boston, MA 02111-1307, USA. | |
| 22 | |
| 23 ;;; Commentary: | |
| 24 | |
| 25 ;;; Code: | |
| 26 | |
| 27 (defconst image-type-regexps | |
| 28 '(("^/\\*.*XPM.\\*/" . xpm) | |
| 29 ("^P[1-6]" . pbm) | |
| 30 ("^GIF8" . gif) | |
| 31 ("JFIF" . jpeg) | |
| 32 ("^\211PNG\r\n" . png) | |
| 33 ("^#define" . xbm) | |
| 34 ("^\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff) | |
| 35 ("^%!PS" . ghostscript)) | |
| 36 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types. | |
| 37 When the first bytes of an image file match REGEXP, it is assumed to | |
| 38 be of image type IMAGE-TYPE.") | |
| 39 | |
| 40 | |
| 41 ;;;###autoload | |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
42 (defun image-type-from-data (data) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
43 "Determine the image type from image data DATA. |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
44 Value is a symbol specifying the image type or nil if type cannot |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
45 be determined." |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
46 (let ((types image-type-regexps) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
47 type) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
48 (while (and types (null type)) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
49 (let ((regexp (car (car types))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
50 (image-type (cdr (car types)))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
51 (when (string-match regexp data) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
52 (setq type image-type)) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
53 (setq types (cdr types)))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
54 type)) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
55 |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
56 |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
57 ;;;###autoload |
| 25003 | 58 (defun image-type-from-file-header (file) |
| 59 "Determine the type of image file FILE from its first few bytes. | |
| 60 Value is a symbol specifying the image type, or nil if type cannot | |
| 61 be determined." | |
| 62 (unless (file-name-directory file) | |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
63 (setq file (expand-file-name file data-directory))) |
| 25003 | 64 (setq file (expand-file-name file)) |
| 65 (let ((header (with-temp-buffer | |
| 66 (insert-file-contents-literally file nil 0 256) | |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
67 (buffer-string)))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
68 (image-type-from-data header))) |
| 25003 | 69 |
| 70 | |
| 71 ;;;###autoload | |
| 72 (defun image-type-available-p (type) | |
| 73 "Value is non-nil if image type TYPE is available. | |
| 74 Image types are symbols like `xbm' or `jpeg'." | |
| 75 (not (null (memq type image-types)))) | |
| 76 | |
| 77 | |
| 78 ;;;###autoload | |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
79 (defun create-image (file-or-data &optional type data-p &rest props) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
80 "Create an image. |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
81 FILE-OR-DATA is an image file name or image data. |
| 25003 | 82 Optional TYPE is a symbol describing the image type. If TYPE is omitted |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
83 or nil, try to determine the image type from its first few bytes |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
84 of image data. If that doesn't work, and FILE-OR-DATA is a file name, |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
85 use its file extension.as image type. |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
86 Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data. |
| 25003 | 87 Optional PROPS are additional image attributes to assign to the image, |
| 88 like, e.g. `:heuristic-mask t'. | |
| 89 Value is the image created, or nil if images of type TYPE are not supported." | |
|
27075
893ec72bd6b1
(create-image, defimage): Don't assume image data is a
Gerd Moellmann <gerd@gnu.org>
parents:
27073
diff
changeset
|
90 (when (and (not data-p) (not (stringp file-or-data))) |
|
893ec72bd6b1
(create-image, defimage): Don't assume image data is a
Gerd Moellmann <gerd@gnu.org>
parents:
27073
diff
changeset
|
91 (error "Invalid image file name `%s'" file-or-data)) |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
92 (cond ((null data-p) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
93 ;; FILE-OR-DATA is a file name. |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
94 (unless (or type |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
95 (setq type (image-type-from-file-header file-or-data))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
96 (let ((extension (file-name-extension file-or-data))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
97 (unless extension |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
98 (error "Cannot determine image type")) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
99 (setq type (intern extension))))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
100 (t |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
101 ;; FILE-OR-DATA contains image data. |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
102 (unless type |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
103 (setq type (image-type-from-data file-or-data))))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
104 (unless type |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
105 (error "Cannot determine image type")) |
| 25003 | 106 (unless (symbolp type) |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
107 (error "Invalid image type `%s'" type)) |
| 25003 | 108 (when (image-type-available-p type) |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
109 (append (list 'image :type type (if data-p :data :file) file-or-data) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
110 props))) |
| 25003 | 111 |
| 112 | |
| 113 ;;;###autoload | |
|
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
114 (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
|
115 "Put image IMAGE in front of POS in the current buffer. |
| 25003 | 116 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
|
117 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
|
118 `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
|
119 image. |
| 25003 | 120 POS may be an integer or marker. |
| 121 AREA is where to display the image. AREA nil or omitted means | |
| 122 display it in the text area, a value of `left-margin' means | |
| 123 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
|
124 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
|
125 (let ((buffer (current-buffer))) |
|
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
126 (unless (eq (car image) 'image) |
|
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
127 (error "Not an image: %s" image)) |
|
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
128 (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
|
129 (error "Invalid area %s" area)) |
|
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
130 (setq string (copy-sequence string)) |
|
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
131 (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
|
132 (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
|
133 (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
|
134 (overlay-put overlay 'put-image t) |
|
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
135 (overlay-put overlay 'before-string string)))) |
| 25003 | 136 |
| 137 | |
| 138 ;;;###autoload | |
|
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
139 (defun insert-image (image string &optional area) |
| 25003 | 140 "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
|
141 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
|
142 with a `display' property whose value is the image. |
| 25003 | 143 AREA is where to display the image. AREA nil or omitted means |
| 144 display it in the text area, a value of `left-margin' means | |
| 145 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
|
146 means display it in the right marginal area." |
| 25003 | 147 (unless (eq (car image) 'image) |
| 148 (error "Not an image: %s" image)) | |
| 149 (unless (or (null area) (memq area '(left-margin right-margin))) | |
| 150 (error "Invalid area %s" area)) | |
|
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
151 (when area |
|
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
152 (setq image (list (list 'margin area) image))) |
|
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
153 (let ((start (point))) |
|
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
154 (insert string) |
|
26007
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
155 ;; Copy `image' so that inserting it twice in a row (adjacently) |
|
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
156 ;; displays two copies of the image. |
|
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
157 (add-text-properties start (point) |
|
26007
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
158 (list 'display (copy-sequence image) |
|
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
159 'intangible (list t) ; something unique |
|
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
160 'rear-nonsticky (list 'display))))) |
|
26007
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
161 |
| 25003 | 162 |
| 163 ;;;###autoload | |
| 164 (defun remove-images (start end &optional buffer) | |
| 165 "Remove images between START and END in BUFFER. | |
| 166 Remove only images that were put in BUFFER with calls to `put-image'. | |
| 167 BUFFER nil or omitted means use the current buffer." | |
| 168 (unless buffer | |
| 169 (setq buffer (current-buffer))) | |
| 170 (let ((overlays (overlays-in start end))) | |
| 171 (while overlays | |
| 172 (let ((overlay (car overlays))) | |
| 173 (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
|
174 (delete-overlay overlay))) |
|
fdc2bd91cf63
(defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents:
25816
diff
changeset
|
175 (setq overlays (cdr overlays))))) |
| 25003 | 176 |
| 177 | |
| 178 ;;;###autoload | |
|
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
179 (defun find-image (specs) |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
180 "Find an image, choosing one of a list of image specifications. |
| 25003 | 181 |
| 182 SPECS is a list of image specifications. DOC is an optional | |
| 183 documentation string. | |
| 184 | |
| 185 Each image specification in SPECS is a property list. The contents of | |
| 186 a specification are image type dependent. All specifications must at | |
|
27059
6bb2a4a0413e
* image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents:
26007
diff
changeset
|
187 least contain the properties `:type TYPE' and either `:file FILE' or |
|
6bb2a4a0413e
* image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents:
26007
diff
changeset
|
188 `:data DATA', where TYPE is a symbol specifying the image type, |
|
6bb2a4a0413e
* image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents:
26007
diff
changeset
|
189 e.g. `xbm', FILE is the file to load the image from, and DATA is a |
|
6bb2a4a0413e
* image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents:
26007
diff
changeset
|
190 string containing the actual image data. The first image |
|
6bb2a4a0413e
* image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents:
26007
diff
changeset
|
191 specification whose TYPE is supported, and FILE exists, is used to |
|
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
192 define SYMBOL." |
| 25003 | 193 (let (image) |
| 194 (while (and specs (null image)) | |
| 195 (let* ((spec (car specs)) | |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
196 (type (plist-get spec :type)) |
|
27059
6bb2a4a0413e
* image.el (defimage): Images with the :data keyword should be considered valid as well.
William M. Perry <wmperry@aventail.com>
parents:
26007
diff
changeset
|
197 (data (plist-get spec :data)) |
|
27921
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
198 (file (plist-get spec :file)) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
199 found) |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
200 (when (image-type-available-p type) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
201 (cond ((stringp file) |
|
27921
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
202 (let ((path load-path)) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
203 (while (and (not found) path) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
204 (let ((try-file (expand-file-name file (car path)))) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
205 (when (file-readable-p try-file) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
206 (setq found try-file))) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
207 (setq path (cdr path))) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
208 (unless found |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
209 (setq found (expand-file-name file data-directory))) |
|
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
210 (setq image (cons 'image (plist-put spec :file found))))) |
|
27075
893ec72bd6b1
(create-image, defimage): Don't assume image data is a
Gerd Moellmann <gerd@gnu.org>
parents:
27073
diff
changeset
|
211 ((not (null data)) |
|
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
212 (setq image (cons 'image spec))))) |
|
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
213 (setq specs (cdr specs)))) |
|
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
214 image)) |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
215 |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
216 |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
217 ;;;###autoload |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
218 (defmacro defimage (symbol specs &optional doc) |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
219 "Define SYMBOL as an image. |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
220 |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
221 SPECS is a list of image specifications. DOC is an optional |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
222 documentation string. |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
223 |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
224 Each image specification in SPECS is a property list. The contents of |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
225 a specification are image type dependent. All specifications must at |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
226 least contain the properties `:type TYPE' and either `:file FILE' or |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
227 `:data DATA', where TYPE is a symbol specifying the image type, |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
228 e.g. `xbm', FILE is the file to load the image from, and DATA is a |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
229 string containing the actual image data. The first image |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
230 specification whose TYPE is supported, and FILE exists, is used to |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
231 define SYMBOL. |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
232 |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
233 Example: |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
234 |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
235 (defimage test-image ((:type xpm :file \"~/test1.xpm\") |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
236 (:type xbm :file \"~/test1.xbm\")))" |
|
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
237 `(defvar ,symbol (find-image ',specs) ,doc)) |
| 25003 | 238 |
| 239 | |
| 240 (provide 'image) | |
| 241 | |
| 25872 | 242 ;;; image.el ends here |
