Mercurial > emacs
annotate lisp/image.el @ 61422:6b6f4fcc8035
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 10 Apr 2005 01:45:58 +0000 |
parents | b0de8a447a79 |
children | f5a3eeaf3d70 30ad2795fdab |
rev | line source |
---|---|
25003 | 1 ;;; image.el --- image API |
2 | |
56106
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
3 ;; Copyright (C) 1998, 99, 2000, 01, 04 Free Software Foundation, Inc. |
42316 | 4 |
5 ;; Maintainer: FSF | |
25309 | 6 ;; Keywords: multimedia |
25003 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
32166 | 29 |
30 (defgroup image () | |
31 "Image support." | |
32 :group 'multimedia) | |
33 | |
34 | |
25003 | 35 (defconst image-type-regexps |
38746
0fc8e4a27edc
(image-type-regexps): Allow whitespace at the start
Gerd Moellmann <gerd@gnu.org>
parents:
38732
diff
changeset
|
36 '(("\\`/[\t\n\r ]*\\*.*XPM.\\*/" . xpm) |
38709
00a56d6da660
(image-type-regexps): Use `\`' instead of `^' in
Gerd Moellmann <gerd@gnu.org>
parents:
37035
diff
changeset
|
37 ("\\`P[1-6]" . pbm) |
00a56d6da660
(image-type-regexps): Use `\`' instead of `^' in
Gerd Moellmann <gerd@gnu.org>
parents:
37035
diff
changeset
|
38 ("\\`GIF8" . gif) |
00a56d6da660
(image-type-regexps): Use `\`' instead of `^' in
Gerd Moellmann <gerd@gnu.org>
parents:
37035
diff
changeset
|
39 ("\\`\211PNG\r\n" . png) |
38746
0fc8e4a27edc
(image-type-regexps): Allow whitespace at the start
Gerd Moellmann <gerd@gnu.org>
parents:
38732
diff
changeset
|
40 ("\\`[\t\n\r ]*#define" . xbm) |
38884
afaef792868d
(image-type-regexps): Make sure that the TIFF
Gerd Moellmann <gerd@gnu.org>
parents:
38794
diff
changeset
|
41 ("\\`\\(MM\0\\*\\|II\\*\0\\)" . tiff) |
38746
0fc8e4a27edc
(image-type-regexps): Allow whitespace at the start
Gerd Moellmann <gerd@gnu.org>
parents:
38732
diff
changeset
|
42 ("\\`[\t\n\r ]*%!PS" . postscript) |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
43 ("\\`\xff\xd8" . (image-jpeg-p . jpeg))) |
25003 | 44 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types. |
45 When the first bytes of an image file match REGEXP, it is assumed to | |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
46 be of image type IMAGE-TYPE if IMAGE-TYPE is a symbol. If not a symbol, |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
47 IMAGE-TYPE must be a pair (PREDICATE . TYPE). PREDICATE is called |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
48 with one argument, a string containing the image data. If PREDICATE returns |
49589
de51db566826
(image-type-regexps): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
49588
diff
changeset
|
49 a non-nil value, TYPE is the image's type.") |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
50 |
56106
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
51 ;;;###autoload |
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
52 (defvar image-library-alist nil |
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
53 "Alist of image types vs external libraries needed to display them. |
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
54 |
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
55 Each element is a list (IMAGE-TYPE LIBRARY...), where the car is a symbol |
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
56 representing a supported image type, and the rest are strings giving |
56189
d2086c9c0507
(image-library-alist): Rewrite docstring in active voice.
Juanma Barranquero <lekktu@gmail.com>
parents:
56106
diff
changeset
|
57 alternate filenames for the corresponding external libraries. |
d2086c9c0507
(image-library-alist): Rewrite docstring in active voice.
Juanma Barranquero <lekktu@gmail.com>
parents:
56106
diff
changeset
|
58 |
d2086c9c0507
(image-library-alist): Rewrite docstring in active voice.
Juanma Barranquero <lekktu@gmail.com>
parents:
56106
diff
changeset
|
59 Emacs tries to load the libraries in the order they appear on the |
d2086c9c0507
(image-library-alist): Rewrite docstring in active voice.
Juanma Barranquero <lekktu@gmail.com>
parents:
56106
diff
changeset
|
60 list; if none is loaded, the running session of Emacs won't |
d2086c9c0507
(image-library-alist): Rewrite docstring in active voice.
Juanma Barranquero <lekktu@gmail.com>
parents:
56106
diff
changeset
|
61 support the image type. Types 'pbm and 'xbm don't need to be |
d2086c9c0507
(image-library-alist): Rewrite docstring in active voice.
Juanma Barranquero <lekktu@gmail.com>
parents:
56106
diff
changeset
|
62 listed; they're always supported.") |
56106
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
63 ;;;###autoload (put 'image-library-alist 'risky-local-variable t) |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
64 |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
65 (defun image-jpeg-p (data) |
46810
65ad7b458435
(image-jpeg-p): Accept "Exif" marker.
Richard M. Stallman <rms@gnu.org>
parents:
43834
diff
changeset
|
66 "Value is non-nil if DATA, a string, consists of JFIF image data. |
65ad7b458435
(image-jpeg-p): Accept "Exif" marker.
Richard M. Stallman <rms@gnu.org>
parents:
43834
diff
changeset
|
67 We accept the tag Exif because that is the same format." |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
68 (when (string-match "\\`\xff\xd8" data) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
69 (catch 'jfif |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
70 (let ((len (length data)) (i 2)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
71 (while (< i len) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
72 (when (/= (aref data i) #xff) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
73 (throw 'jfif nil)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
74 (setq i (1+ i)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
75 (when (>= (+ i 2) len) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
76 (throw 'jfif nil)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
77 (let ((nbytes (+ (lsh (aref data (+ i 1)) 8) |
38776
a679a282d5cb
(image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents:
38746
diff
changeset
|
78 (aref data (+ i 2)))) |
a679a282d5cb
(image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents:
38746
diff
changeset
|
79 (code (aref data i))) |
a679a282d5cb
(image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents:
38746
diff
changeset
|
80 (when (and (>= code #xe0) (<= code #xef)) |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
81 ;; APP0 LEN1 LEN2 "JFIF\0" |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48130
diff
changeset
|
82 (throw 'jfif |
52344
f1fd0b3a923e
(image-jpeg-p): Don't search beyond length of data.
John Paul Wallington <jpw@pobox.com>
parents:
49589
diff
changeset
|
83 (string-match "JFIF\\|Exif" |
f1fd0b3a923e
(image-jpeg-p): Don't search beyond length of data.
John Paul Wallington <jpw@pobox.com>
parents:
49589
diff
changeset
|
84 (substring data i (min (+ i nbytes) len))))) |
38746
0fc8e4a27edc
(image-type-regexps): Allow whitespace at the start
Gerd Moellmann <gerd@gnu.org>
parents:
38732
diff
changeset
|
85 (setq i (+ i 1 nbytes)))))))) |
25003 | 86 |
87 | |
88 ;;;###autoload | |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
89 (defun image-type-from-data (data) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
90 "Determine the image type from image data DATA. |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
91 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
|
92 be determined." |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
93 (let ((types image-type-regexps) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
94 type) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
95 (while (and types (null type)) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
96 (let ((regexp (car (car types))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
97 (image-type (cdr (car types)))) |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
98 (when (or (and (symbolp image-type) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
99 (string-match regexp data)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
100 (and (consp image-type) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
101 (funcall (car image-type) data) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
102 (setq image-type (cdr image-type)))) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
103 (setq type image-type)) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
104 (setq types (cdr types)))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
105 type)) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
106 |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
107 |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
108 ;;;###autoload |
25003 | 109 (defun image-type-from-file-header (file) |
110 "Determine the type of image file FILE from its first few bytes. | |
111 Value is a symbol specifying the image type, or nil if type cannot | |
112 be determined." | |
113 (unless (file-name-directory file) | |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
114 (setq file (expand-file-name file data-directory))) |
25003 | 115 (setq file (expand-file-name file)) |
116 (let ((header (with-temp-buffer | |
43834
aa881082fd04
(image-type-from-file-header): Make temporary buffer unibyte.
Pavel Janík <Pavel@Janik.cz>
parents:
42316
diff
changeset
|
117 (set-buffer-multibyte nil) |
25003 | 118 (insert-file-contents-literally file nil 0 256) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
119 (buffer-string)))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
120 (image-type-from-data header))) |
25003 | 121 |
122 | |
123 ;;;###autoload | |
124 (defun image-type-available-p (type) | |
125 "Value is non-nil if image type TYPE is available. | |
126 Image types are symbols like `xbm' or `jpeg'." | |
56106
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
127 (and (fboundp 'init-image-library) |
5b3f0e4cf47f
(image-library-alist): New variable to map image types to external
Juanma Barranquero <lekktu@gmail.com>
parents:
55167
diff
changeset
|
128 (init-image-library type image-library-alist))) |
25003 | 129 |
130 ;;;###autoload | |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
131 (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
|
132 "Create an image. |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
133 FILE-OR-DATA is an image file name or image data. |
25003 | 134 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
|
135 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
|
136 of image data. If that doesn't work, and FILE-OR-DATA is a file name, |
34378
5ae7af279df7
(create-image): Doc fix; spotted by Per Cederqvist <ceder@lysator.liu.se>.
Eli Zaretskii <eliz@gnu.org>
parents:
32166
diff
changeset
|
137 use its file extension as image type. |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
138 Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data. |
25003 | 139 Optional PROPS are additional image attributes to assign to the image, |
31635 | 140 like, e.g. `:mask MASK'. |
25003 | 141 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
|
142 (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
|
143 (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
|
144 (cond ((null data-p) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
145 ;; FILE-OR-DATA is a file name. |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
146 (unless (or type |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
147 (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
|
148 (let ((extension (file-name-extension file-or-data))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
149 (unless extension |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
150 (error "Cannot determine image type")) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
151 (setq type (intern extension))))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
152 (t |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
153 ;; FILE-OR-DATA contains image data. |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
154 (unless type |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
155 (setq type (image-type-from-data file-or-data))))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
156 (unless type |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
157 (error "Cannot determine image type")) |
25003 | 158 (unless (symbolp type) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
159 (error "Invalid image type `%s'" type)) |
25003 | 160 (when (image-type-available-p type) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
161 (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
|
162 props))) |
25003 | 163 |
164 | |
165 ;;;###autoload | |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
166 (defun put-image (image pos &optional string area) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
167 "Put image IMAGE in front of POS in the current buffer. |
25003 | 168 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
|
169 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
|
170 `before-string' STRING that has a `display' property whose value is the |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
171 image. STRING is defaulted if you omit it. |
25003 | 172 POS may be an integer or marker. |
173 AREA is where to display the image. AREA nil or omitted means | |
174 display it in the text area, a value of `left-margin' means | |
175 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
|
176 means display it in the right marginal area." |
29626
ecb96a7369d3
Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents:
29624
diff
changeset
|
177 (unless string (setq string "x")) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
178 (let ((buffer (current-buffer))) |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
179 (unless (eq (car-safe image) 'image) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
180 (error "Not an image: %s" image)) |
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
181 (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
|
182 (error "Invalid area %s" area)) |
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
183 (setq string (copy-sequence string)) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
184 (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
|
185 (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
|
186 (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
|
187 (overlay-put overlay 'put-image t) |
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
188 (overlay-put overlay 'before-string string)))) |
25003 | 189 |
190 | |
191 ;;;###autoload | |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
192 (defun insert-image (image &optional string area slice) |
25003 | 193 "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
|
194 IMAGE is displayed by inserting STRING into the current buffer |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
195 with a `display' property whose value is the image. STRING is |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
196 defaulted if you omit it. |
25003 | 197 AREA is where to display the image. AREA nil or omitted means |
198 display it in the text area, a value of `left-margin' means | |
199 display it in the left marginal area, a value of `right-margin' | |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
200 means display it in the right marginal area. |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
201 SLICE specifies slice of IMAGE to insert. SLICE nil or omitted |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
202 means insert whole image. SLICE is a list (X Y WIDTH HEIGHT) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
203 specifying the X and Y positions and WIDTH and HEIGHT of image area |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
204 to insert. A float value 0.0 - 1.0 means relative to the width or |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
205 height of the image; integer values are taken as pixel values." |
29626
ecb96a7369d3
Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents:
29624
diff
changeset
|
206 ;; Use a space as least likely to cause trouble when it's a hidden |
ecb96a7369d3
Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents:
29624
diff
changeset
|
207 ;; character in the buffer. |
ecb96a7369d3
Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents:
29624
diff
changeset
|
208 (unless string (setq string " ")) |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
209 (unless (eq (car-safe image) 'image) |
25003 | 210 (error "Not an image: %s" image)) |
211 (unless (or (null area) (memq area '(left-margin right-margin))) | |
212 (error "Invalid area %s" area)) | |
29607
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
213 (if area |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
214 (setq image (list (list 'margin area) image)) |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
215 ;; Cons up a new spec equal but not eq to `image' so that |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
216 ;; inserting it twice in a row (adjacently) displays two copies of |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
217 ;; the image. Don't try to avoid this by looking at the display |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
218 ;; properties on either side so that we DTRT more often with |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
219 ;; cut-and-paste. (Yanking killed image text next to another copy |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
220 ;; of it loses anyway.) |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
221 (setq image (cons 'image (cdr image)))) |
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
222 (let ((start (point))) |
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
223 (insert string) |
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
224 (add-text-properties start (point) |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
225 `(display ,(if slice |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
226 (list (cons 'slice slice) image) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
227 image) rear-nonsticky (display))))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
228 |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
229 |
60688
b0de8a447a79
(insert-sliced-image): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
59276
diff
changeset
|
230 ;;;###autoload |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
231 (defun insert-sliced-image (image &optional string area rows cols) |
57196
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
232 "Insert IMAGE into current buffer at point. |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
233 IMAGE is displayed by inserting STRING into the current buffer |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
234 with a `display' property whose value is the image. STRING is |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
235 defaulted if you omit it. |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
236 AREA is where to display the image. AREA nil or omitted means |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
237 display it in the text area, a value of `left-margin' means |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
238 display it in the left marginal area, a value of `right-margin' |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
239 means display it in the right marginal area. |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
240 The image is automatically split into ROW x COLS slices." |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
241 (unless string (setq string " ")) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
242 (unless (eq (car-safe image) 'image) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
243 (error "Not an image: %s" image)) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
244 (unless (or (null area) (memq area '(left-margin right-margin))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
245 (error "Invalid area %s" area)) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
246 (if area |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
247 (setq image (list (list 'margin area) image)) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
248 ;; Cons up a new spec equal but not eq to `image' so that |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
249 ;; inserting it twice in a row (adjacently) displays two copies of |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
250 ;; the image. Don't try to avoid this by looking at the display |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
251 ;; properties on either side so that we DTRT more often with |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
252 ;; cut-and-paste. (Yanking killed image text next to another copy |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
253 ;; of it loses anyway.) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
254 (setq image (cons 'image (cdr image)))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
255 (let ((x 0.0) (dx (/ 1.0001 (or cols 1))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
256 (y 0.0) (dy (/ 1.0001 (or rows 1)))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
257 (while (< y 1.0) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
258 (while (< x 1.0) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
259 (let ((start (point))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
260 (insert string) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
261 (add-text-properties start (point) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
262 `(display ,(list (list 'slice x y dx dy) image) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
263 rear-nonsticky (display))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
264 (setq x (+ x dx)))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
265 (setq x 0.0 |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
266 y (+ y dy)) |
59276
d50d807507e0
(insert-sliced-image): Use t for line-height property.
Kim F. Storm <storm@cua.dk>
parents:
57196
diff
changeset
|
267 (insert (propertize "\n" 'line-height t))))) |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
268 |
26007
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
269 |
25003 | 270 |
271 ;;;###autoload | |
272 (defun remove-images (start end &optional buffer) | |
273 "Remove images between START and END in BUFFER. | |
274 Remove only images that were put in BUFFER with calls to `put-image'. | |
275 BUFFER nil or omitted means use the current buffer." | |
276 (unless buffer | |
277 (setq buffer (current-buffer))) | |
278 (let ((overlays (overlays-in start end))) | |
279 (while overlays | |
280 (let ((overlay (car overlays))) | |
281 (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
|
282 (delete-overlay overlay))) |
fdc2bd91cf63
(defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents:
25816
diff
changeset
|
283 (setq overlays (cdr overlays))))) |
25003 | 284 |
285 | |
286 ;;;###autoload | |
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
287 (defun find-image (specs) |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
288 "Find an image, choosing one of a list of image specifications. |
25003 | 289 |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
290 SPECS is a list of image specifications. |
25003 | 291 |
292 Each image specification in SPECS is a property list. The contents of | |
293 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
|
294 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
|
295 `: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
|
296 e.g. `xbm', FILE is the file to load the image from, and DATA is a |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
297 string containing the actual image data. The specification whose TYPE |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
298 is supported, and FILE exists, is used to construct the image |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
299 specification to be returned. Return nil if no specification is |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
300 satisfied. |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
301 |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
302 The image is looked for first on `load-path' and then in `data-directory'." |
25003 | 303 (let (image) |
304 (while (and specs (null image)) | |
305 (let* ((spec (car specs)) | |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
306 (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
|
307 (data (plist-get spec :data)) |
27921
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
308 (file (plist-get spec :file)) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
309 found) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
310 (when (image-type-available-p type) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
311 (cond ((stringp file) |
27921
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
312 (let ((path load-path)) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
313 (while (and (not found) path) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
314 (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
|
315 (when (file-readable-p try-file) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
316 (setq found try-file))) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
317 (setq path (cdr path))) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
318 (unless found |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
319 (let ((try-file (expand-file-name file data-directory))) |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
320 (if (file-readable-p try-file) |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
321 (setq found try-file)))) |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
322 (if found |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
323 (setq image |
30952
5042a3b24c96
(find-image): Copy `spec' before using plist-put.
Dave Love <fx@gnu.org>
parents:
29626
diff
changeset
|
324 (cons 'image (plist-put (copy-sequence spec) |
5042a3b24c96
(find-image): Copy `spec' before using plist-put.
Dave Love <fx@gnu.org>
parents:
29626
diff
changeset
|
325 :file found)))))) |
27075
893ec72bd6b1
(create-image, defimage): Don't assume image data is a
Gerd Moellmann <gerd@gnu.org>
parents:
27073
diff
changeset
|
326 ((not (null data)) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
327 (setq image (cons 'image spec))))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
328 (setq specs (cdr specs)))) |
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
329 image)) |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
330 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
331 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
332 ;;;###autoload |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
333 (defmacro defimage (symbol specs &optional doc) |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
334 "Define SYMBOL as an image. |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
335 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
336 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
|
337 documentation string. |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
338 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
339 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
|
340 a specification are image type dependent. All specifications must at |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
341 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
|
342 `: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
|
343 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
|
344 string containing the actual image data. The first image |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
345 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
|
346 define SYMBOL. |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
347 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
348 Example: |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
349 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
350 (defimage test-image ((:type xpm :file \"~/test1.xpm\") |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
351 (:type xbm :file \"~/test1.xbm\")))" |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
352 `(defvar ,symbol (find-image ',specs) ,doc)) |
25003 | 353 |
354 | |
355 (provide 'image) | |
356 | |
52401 | 357 ;;; arch-tag: 8e76a07b-eb48-4f3e-a7a0-1a7ba9f096b3 |
25872 | 358 ;;; image.el ends here |