Mercurial > emacs
annotate lisp/image.el @ 75066:9cb86600aa59
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 02 Jan 2007 23:57:14 +0000 |
parents | 94afc7cac404 |
children | 1ec77a44faf9 bc10a33dd40b |
rev | line source |
---|---|
25003 | 1 ;;; image.el --- image API |
2 | |
64762
41bb365f41c4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64091
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, |
68651
3bd95f4f2941
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
66402
diff
changeset
|
4 ;; 2004, 2005, 2006 Free Software Foundation, Inc. |
42316 | 5 |
6 ;; Maintainer: FSF | |
25309 | 7 ;; Keywords: multimedia |
25003 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
25003 | 25 |
26 ;;; Commentary: | |
27 | |
28 ;;; Code: | |
29 | |
32166 | 30 |
31 (defgroup image () | |
32 "Image support." | |
33 :group 'multimedia) | |
34 | |
35 | |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
36 (defconst image-type-header-regexps |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
37 '(("\\`/[\t\n\r ]*\\*.*XPM.\\*/" . xpm) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
38 ("\\`P[1-6][[:space:]]+\\(?:#.*[[:space:]]+\\)*[0-9]+[[:space:]]+[0-9]+" . pbm) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
39 ("\\`GIF8" . gif) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
40 ("\\`\x89PNG\r\n\x1a\n" . png) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
41 ("\\`[\t\n\r ]*#define" . xbm) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
42 ("\\`\\(?:MM\0\\*\\|II\\*\0\\)" . tiff) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
43 ("\\`[\t\n\r ]*%!PS" . postscript) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
44 ("\\`\xff\xd8" . (image-jpeg-p . jpeg))) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
45 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types. |
25003 | 46 When the first bytes of an image file match REGEXP, it is assumed to |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
47 be of image type IMAGE-TYPE if IMAGE-TYPE is a symbol. If not a symbol, |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
48 IMAGE-TYPE must be a pair (PREDICATE . TYPE). PREDICATE is called |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
49 with one argument, a string containing the image data. If PREDICATE returns |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
50 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
|
51 |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
52 (defconst image-type-file-name-regexps |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
53 '(("\\.png\\'" . png) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
54 ("\\.gif\\'" . gif) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
55 ("\\.jpe?g\\'" . jpeg) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
56 ("\\.bmp\\'" . bmp) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
57 ("\\.xpm\\'" . xpm) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
58 ("\\.pbm\\'" . pbm) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
59 ("\\.xbm\\'" . xbm) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
60 ("\\.ps\\'" . postscript) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
61 ("\\.tiff?\\'" . tiff)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
62 "Alist of (REGEXP . IMAGE-TYPE) pairs used to identify image files. |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
63 When the name of an image file match REGEXP, it is assumed to |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
64 be of image type IMAGE-TYPE.") |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
65 |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
66 (defvar image-type-auto-detectable |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
67 '((pbm . t) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
68 (xbm . t) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
69 (bmp . maybe) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
70 (gif . maybe) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
71 (png . maybe) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
72 (xpm . maybe) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
73 (jpeg . maybe) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
74 (tiff . maybe) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
75 (postscript . nil)) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
76 "Alist of (IMAGE-TYPE . AUTODETECT) pairs used to auto-detect image files. |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
77 \(See `image-type-auto-detected-p'). |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
78 |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
79 AUTODETECT can be |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
80 - t always auto-detect. |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
81 - nil never auto-detect. |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
82 - maybe auto-detect only if the image type is available |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
83 (see `image-type-available-p').") |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
84 |
66307
ca953a3dbdf1
(image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents:
66296
diff
changeset
|
85 (defvar image-load-path nil |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
86 "List of locations in which to search for image files. |
65599
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
87 If an element is a string, it defines a directory to search. |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
88 If an element is a variable symbol whose value is a string, that |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
89 value defines a directory to search. |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
90 If an element is a variable symbol whose value is a list, the |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
91 value is used as a list of directories to search.") |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
92 |
66307
ca953a3dbdf1
(image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents:
66296
diff
changeset
|
93 (eval-at-startup |
ca953a3dbdf1
(image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents:
66296
diff
changeset
|
94 (setq image-load-path |
ca953a3dbdf1
(image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents:
66296
diff
changeset
|
95 (list (file-name-as-directory (expand-file-name "images" data-directory)) |
ca953a3dbdf1
(image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents:
66296
diff
changeset
|
96 'data-directory 'load-path))) |
ca953a3dbdf1
(image-load-path): Use eval-at-startup to initialize.
Richard M. Stallman <rms@gnu.org>
parents:
66296
diff
changeset
|
97 |
69471
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
98 |
69365
0a2d89023fde
(image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents:
69360
diff
changeset
|
99 (defun image-load-path-for-library (library image &optional path no-error) |
69569
dd7f85a6af09
(image-load-path-for-library): Shorten first line in docstring.
Bill Wohler <wohler@newt.com>
parents:
69535
diff
changeset
|
100 "Return a suitable search path for images used by LIBRARY. |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
101 |
69535
3feef8dfbff5
(image-load-path-for-library): Minor docstring fix.
Bill Wohler <wohler@newt.com>
parents:
69516
diff
changeset
|
102 It searches for IMAGE in `image-load-path' (excluding |
69516
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
103 \"`data-directory'/images\") and `load-path', followed by a path |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
104 suitable for LIBRARY, which includes \"../../etc/images\" and |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
105 \"../etc/images\" relative to the library file itself, and then |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
106 in \"`data-directory'/images\". |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
107 |
69471
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
108 Then this function returns a list of directories which contains |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
109 first the directory in which IMAGE was found, followed by the |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
110 value of `load-path'. If PATH is given, it is used instead of |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
111 `load-path'. |
69365
0a2d89023fde
(image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents:
69360
diff
changeset
|
112 |
69471
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
113 If NO-ERROR is non-nil and a suitable path can't be found, don't |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
114 signal an error. Instead, return a list of directories as before, |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
115 except that nil appears in place of the image directory. |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
116 |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
117 Here is an example that uses a common idiom to provide |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
118 compatibility with versions of Emacs that lack the variable |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
119 `image-load-path': |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
120 |
69493
4f9233243d97
(image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents:
69471
diff
changeset
|
121 ;; Shush compiler. |
4f9233243d97
(image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents:
69471
diff
changeset
|
122 (defvar image-load-path) |
69471
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
123 |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
124 (let* ((load-path (image-load-path-for-library \"mh-e\" \"mh-logo.xpm\")) |
69493
4f9233243d97
(image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents:
69471
diff
changeset
|
125 (image-load-path (cons (car load-path) |
4f9233243d97
(image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents:
69471
diff
changeset
|
126 (when (boundp 'image-load-path) |
4f9233243d97
(image-load-path-for-library): Fix example by not recommending that
Bill Wohler <wohler@newt.com>
parents:
69471
diff
changeset
|
127 image-load-path)))) |
69471
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
128 (mh-tool-bar-folder-buttons-init))" |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
129 (unless library (error "No library specified")) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
130 (unless image (error "No image specified")) |
69516
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
131 (let (image-directory image-directory-load-path) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
132 ;; Check for images in image-load-path or load-path. |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
133 (let ((img image) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
134 (dir (or |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
135 ;; Images in image-load-path. |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
136 (image-search-load-path image) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
137 ;; Images in load-path. |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
138 (locate-library image))) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
139 parent) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
140 ;; Since the image might be in a nested directory (for |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
141 ;; example, mail/attach.pbm), adjust `image-directory' |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
142 ;; accordingly. |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
143 (when dir |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
144 (setq dir (file-name-directory dir)) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
145 (while (setq parent (file-name-directory img)) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
146 (setq img (directory-file-name parent) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
147 dir (expand-file-name "../" dir)))) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
148 (setq image-directory-load-path dir)) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
149 |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
150 ;; If `image-directory-load-path' isn't Emacs' image directory, |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
151 ;; it's probably a user preference, so use it. Then use a |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
152 ;; relative setting if possible; otherwise, use |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
153 ;; `image-directory-load-path'. |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
154 (cond |
69516
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
155 ;; User-modified image-load-path? |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
156 ((and image-directory-load-path |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
157 (not (equal image-directory-load-path |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
158 (file-name-as-directory |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
159 (expand-file-name "images" data-directory))))) |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
160 (setq image-directory image-directory-load-path)) |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
161 ;; Try relative setting. |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
162 ((let (library-name d1ei d2ei) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
163 ;; First, find library in the load-path. |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
164 (setq library-name (locate-library library)) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
165 (if (not library-name) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
166 (error "Cannot find library %s in load-path" library)) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
167 ;; And then set image-directory relative to that. |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
168 (setq |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
169 ;; Go down 2 levels. |
69516
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
170 d2ei (file-name-as-directory |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
171 (expand-file-name |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
172 (concat (file-name-directory library-name) "../../etc/images"))) |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
173 ;; Go down 1 level. |
69516
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
174 d1ei (file-name-as-directory |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
175 (expand-file-name |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
176 (concat (file-name-directory library-name) "../etc/images")))) |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
177 (setq image-directory |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
178 ;; Set it to nil if image is not found. |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
179 (cond ((file-exists-p (expand-file-name image d2ei)) d2ei) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
180 ((file-exists-p (expand-file-name image d1ei)) d1ei))))) |
69516
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
181 ;; Use Emacs' image directory. |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
182 (image-directory-load-path |
e419733d5cf6
(image-load-path-for-library): Prefer user's images in
Bill Wohler <wohler@newt.com>
parents:
69493
diff
changeset
|
183 (setq image-directory image-directory-load-path)) |
69365
0a2d89023fde
(image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents:
69360
diff
changeset
|
184 (no-error |
0a2d89023fde
(image-load-path-for-library): Merged changes from Reiner. Add
Bill Wohler <wohler@newt.com>
parents:
69360
diff
changeset
|
185 (message "Could not find image %s for library %s" image library)) |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
186 (t |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
187 (error "Could not find image %s for library %s" image library))) |
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
188 |
69471
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
189 ;; Return an augmented `path' or `load-path'. |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
190 (nconc (list image-directory) |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
191 (delete image-directory (copy-sequence (or path load-path)))))) |
6f07bf99b6f8
(image-load-path-for-library): Pass value of path rather than symbol.
Bill Wohler <wohler@newt.com>
parents:
69365
diff
changeset
|
192 |
69360
e5e4303f8050
(image-load-path-for-library): Merge at least three functions from
Bill Wohler <wohler@newt.com>
parents:
68651
diff
changeset
|
193 |
38732
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
194 (defun image-jpeg-p (data) |
46810
65ad7b458435
(image-jpeg-p): Accept "Exif" marker.
Richard M. Stallman <rms@gnu.org>
parents:
43834
diff
changeset
|
195 "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
|
196 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
|
197 (when (string-match "\\`\xff\xd8" data) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
198 (catch 'jfif |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
199 (let ((len (length data)) (i 2)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
200 (while (< i len) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
201 (when (/= (aref data i) #xff) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
202 (throw 'jfif nil)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
203 (setq i (1+ i)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
204 (when (>= (+ i 2) len) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
205 (throw 'jfif nil)) |
24fe4f884e82
(image-type-regexps): Allow predicates. Change the way
Gerd Moellmann <gerd@gnu.org>
parents:
38711
diff
changeset
|
206 (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
|
207 (aref data (+ i 2)))) |
a679a282d5cb
(image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents:
38746
diff
changeset
|
208 (code (aref data i))) |
a679a282d5cb
(image-jpeg-p): Test for APPn markers in the range
Gerd Moellmann <gerd@gnu.org>
parents:
38746
diff
changeset
|
209 (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
|
210 ;; APP0 LEN1 LEN2 "JFIF\0" |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48130
diff
changeset
|
211 (throw 'jfif |
52344
f1fd0b3a923e
(image-jpeg-p): Don't search beyond length of data.
John Paul Wallington <jpw@pobox.com>
parents:
49589
diff
changeset
|
212 (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
|
213 (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
|
214 (setq i (+ i 1 nbytes)))))))) |
25003 | 215 |
216 | |
217 ;;;###autoload | |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
218 (defun image-type-from-data (data) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
219 "Determine the image type from image data DATA. |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
220 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
|
221 be determined." |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
222 (let ((types image-type-header-regexps) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
223 type) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
224 (while types |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
225 (let ((regexp (car (car types))) |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
226 (image-type (cdr (car types)))) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
227 (if (or (and (symbolp image-type) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
228 (string-match regexp data)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
229 (and (consp image-type) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
230 (funcall (car image-type) data) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
231 (setq image-type (cdr image-type)))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
232 (setq type image-type |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
233 types nil) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
234 (setq types (cdr types))))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
235 type)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
236 |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
237 |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
238 ;;;###autoload |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
239 (defun image-type-from-buffer () |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
240 "Determine the image type from data in the current buffer. |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
241 Value is a symbol specifying the image type or nil if type cannot |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
242 be determined." |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
243 (let ((types image-type-header-regexps) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
244 type |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
245 (opoint (point))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
246 (goto-char (point-min)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
247 (while types |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
248 (let ((regexp (car (car types))) |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
249 (image-type (cdr (car types))) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
250 data) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
251 (if (or (and (symbolp image-type) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
252 (looking-at regexp)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
253 (and (consp image-type) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
254 (funcall (car image-type) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
255 (or data |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
256 (setq data |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
257 (buffer-substring |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
258 (point-min) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
259 (min (point-max) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
260 (+ (point-min) 256)))))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
261 (setq image-type (cdr image-type)))) |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
262 (setq type image-type |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
263 types nil) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
264 (setq types (cdr types))))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
265 (goto-char opoint) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
266 type)) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
267 |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
268 |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
269 ;;;###autoload |
25003 | 270 (defun image-type-from-file-header (file) |
271 "Determine the type of image file FILE from its first few bytes. | |
272 Value is a symbol specifying the image type, or nil if type cannot | |
273 be determined." | |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
274 (unless (or (file-readable-p file) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
275 (file-name-absolute-p file)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
276 (setq file (image-search-load-path file))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
277 (and file |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
278 (file-readable-p file) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
279 (with-temp-buffer |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
280 (set-buffer-multibyte nil) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
281 (insert-file-contents-literally file nil 0 256) |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
282 (image-type-from-buffer)))) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
283 |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
284 |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
285 ;;;###autoload |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
286 (defun image-type-from-file-name (file) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
287 "Determine the type of image file FILE from its name. |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
288 Value is a symbol specifying the image type, or nil if type cannot |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
289 be determined." |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
290 (let ((types image-type-file-name-regexps) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
291 type) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
292 (while types |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
293 (if (string-match (car (car types)) file) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
294 (setq type (cdr (car types)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
295 types nil) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
296 (setq types (cdr types)))) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
297 type)) |
25003 | 298 |
299 | |
300 ;;;###autoload | |
70170
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
301 (defun image-type (file-or-data &optional type data-p) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
302 "Determine and return image type. |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
303 FILE-OR-DATA is an image file name or image data. |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
304 Optional TYPE is a symbol describing the image type. If TYPE is omitted |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
305 or nil, try to determine the image type from its first few bytes |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
306 of image data. If that doesn't work, and FILE-OR-DATA is a file name, |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
307 use its file extension as image type. |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
308 Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data." |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
309 (when (and (not data-p) (not (stringp file-or-data))) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
310 (error "Invalid image file name `%s'" file-or-data)) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
311 (cond ((null data-p) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
312 ;; FILE-OR-DATA is a file name. |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
313 (unless (or type |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
314 (setq type (image-type-from-file-header file-or-data))) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
315 (let ((extension (file-name-extension file-or-data))) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
316 (unless extension |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
317 (error "Cannot determine image type")) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
318 (setq type (intern extension))))) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
319 (t |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
320 ;; FILE-OR-DATA contains image data. |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
321 (unless type |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
322 (setq type (image-type-from-data file-or-data))))) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
323 (unless type |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
324 (error "Cannot determine image type")) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
325 (unless (symbolp type) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
326 (error "Invalid image type `%s'" type)) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
327 type) |
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
328 |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
329 |
70170
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
330 ;;;###autoload |
25003 | 331 (defun image-type-available-p (type) |
62816
f5a3eeaf3d70
(image-library-alist): Moved to image.c.
Juanma Barranquero <lekktu@gmail.com>
parents:
60688
diff
changeset
|
332 "Return non-nil if image type TYPE is available. |
25003 | 333 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
|
334 (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
|
335 (init-image-library type image-library-alist))) |
25003 | 336 |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
337 |
25003 | 338 ;;;###autoload |
74972
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
339 (defun image-type-auto-detected-p () |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
340 "Return t iff the current buffer contains an auto-detectable image. |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
341 Whether image types are auto-detectable or not depends on the setting |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
342 of the variable `image-type-auto-detectable'. |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
343 |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
344 This function is intended to be used from `magic-mode-alist' (which see)." |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
345 (let* ((type (image-type-from-buffer)) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
346 (auto (and type (cdr (assq type image-type-auto-detectable))))) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
347 (and auto |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
348 (or (eq auto t) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
349 (image-type-available-p type))))) |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
350 |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
351 |
94afc7cac404
(image-type-header-regexps, image-type-from-data, image-type-from-buffer,
Juanma Barranquero <lekktu@gmail.com>
parents:
74916
diff
changeset
|
352 ;;;###autoload |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
353 (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
|
354 "Create an image. |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
355 FILE-OR-DATA is an image file name or image data. |
25003 | 356 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
|
357 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
|
358 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
|
359 use its file extension as image type. |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
360 Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data. |
25003 | 361 Optional PROPS are additional image attributes to assign to the image, |
31635 | 362 like, e.g. `:mask MASK'. |
66196
2e59eea25fcf
* image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents:
65599
diff
changeset
|
363 Value is the image created, or nil if images of type TYPE are not supported. |
2e59eea25fcf
* image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents:
65599
diff
changeset
|
364 |
2e59eea25fcf
* image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents:
65599
diff
changeset
|
365 Images should not be larger than specified by `max-image-size'." |
70170
de6c9508749d
(image-type): New defun split out of create-image.
Kim F. Storm <storm@cua.dk>
parents:
69569
diff
changeset
|
366 (setq type (image-type file-or-data type data-p)) |
25003 | 367 (when (image-type-available-p type) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
368 (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
|
369 props))) |
25003 | 370 |
371 | |
372 ;;;###autoload | |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
373 (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
|
374 "Put image IMAGE in front of POS in the current buffer. |
25003 | 375 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
|
376 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
|
377 `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
|
378 image. STRING is defaulted if you omit it. |
25003 | 379 POS may be an integer or marker. |
380 AREA is where to display the image. AREA nil or omitted means | |
381 display it in the text area, a value of `left-margin' means | |
382 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
|
383 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
|
384 (unless string (setq string "x")) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
385 (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
|
386 (unless (eq (car-safe image) 'image) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
387 (error "Not an image: %s" image)) |
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
388 (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
|
389 (error "Invalid area %s" area)) |
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
390 (setq string (copy-sequence string)) |
25617
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
391 (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
|
392 (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
|
393 (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
|
394 (overlay-put overlay 'put-image t) |
697b28471784
(put-image): Remove optional buffer parameter.
Gerd Moellmann <gerd@gnu.org>
parents:
25309
diff
changeset
|
395 (overlay-put overlay 'before-string string)))) |
25003 | 396 |
397 | |
398 ;;;###autoload | |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
399 (defun insert-image (image &optional string area slice) |
25003 | 400 "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
|
401 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
|
402 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
|
403 defaulted if you omit it. |
25003 | 404 AREA is where to display the image. AREA nil or omitted means |
405 display it in the text area, a value of `left-margin' means | |
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 ;; 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
|
414 ;; character in the buffer. |
ecb96a7369d3
Fix last change to be in insert-image as intended.
Dave Love <fx@gnu.org>
parents:
29624
diff
changeset
|
415 (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
|
416 (unless (eq (car-safe image) 'image) |
25003 | 417 (error "Not an image: %s" image)) |
418 (unless (or (null area) (memq area '(left-margin right-margin))) | |
419 (error "Invalid area %s" area)) | |
29607
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
420 (if area |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
421 (setq image (list (list 'margin area) image)) |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
422 ;; 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
|
423 ;; 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
|
424 ;; 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
|
425 ;; 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
|
426 ;; 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
|
427 ;; of it loses anyway.) |
42d156d8d8eb
(insert-image): Save a little consing.
Dave Love <fx@gnu.org>
parents:
29470
diff
changeset
|
428 (setq image (cons 'image (cdr image)))) |
25816
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
429 (let ((start (point))) |
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
430 (insert string) |
2d53a03a3baa
(put-image, insert-image): Add string argument.
Gerd Moellmann <gerd@gnu.org>
parents:
25617
diff
changeset
|
431 (add-text-properties start (point) |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
432 `(display ,(if slice |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
433 (list (cons 'slice slice) image) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
434 image) rear-nonsticky (display))))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
435 |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
436 |
60688
b0de8a447a79
(insert-sliced-image): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
59276
diff
changeset
|
437 ;;;###autoload |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
438 (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
|
439 "Insert IMAGE into current buffer at point. |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
440 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
|
441 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
|
442 defaulted if you omit it. |
090c23fa222c
(insert-sliced-image): Add doc string.
Kim F. Storm <storm@cua.dk>
parents:
56189
diff
changeset
|
443 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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 (unless string (setq string " ")) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
449 (unless (eq (car-safe image) 'image) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
450 (error "Not an image: %s" image)) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
451 (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
|
452 (error "Invalid area %s" area)) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
453 (if area |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
454 (setq image (list (list 'margin area) image)) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
455 ;; 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
|
456 ;; 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
|
457 ;; 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
|
458 ;; 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
|
459 ;; 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
|
460 ;; of it loses anyway.) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
461 (setq image (cons 'image (cdr image)))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
462 (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
|
463 (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
|
464 (while (< y 1.0) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
465 (while (< x 1.0) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
466 (let ((start (point))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
467 (insert string) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
468 (add-text-properties start (point) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
469 `(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
|
470 rear-nonsticky (display))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
471 (setq x (+ x dx)))) |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
472 (setq x 0.0 |
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
473 y (+ y dy)) |
59276
d50d807507e0
(insert-sliced-image): Use t for line-height property.
Kim F. Storm <storm@cua.dk>
parents:
57196
diff
changeset
|
474 (insert (propertize "\n" 'line-height t))))) |
55033
a7dfcd60873e
(insert-image): Add optional SLICE arg.
Kim F. Storm <storm@cua.dk>
parents:
52401
diff
changeset
|
475 |
26007
774b2504710b
(insert-image): Copy the image spec and add an intangible property.
Dave Love <fx@gnu.org>
parents:
25872
diff
changeset
|
476 |
25003 | 477 |
478 ;;;###autoload | |
479 (defun remove-images (start end &optional buffer) | |
480 "Remove images between START and END in BUFFER. | |
481 Remove only images that were put in BUFFER with calls to `put-image'. | |
482 BUFFER nil or omitted means use the current buffer." | |
483 (unless buffer | |
484 (setq buffer (current-buffer))) | |
485 (let ((overlays (overlays-in start end))) | |
486 (while overlays | |
487 (let ((overlay (car overlays))) | |
488 (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
|
489 (delete-overlay overlay))) |
fdc2bd91cf63
(defimage): Remove redundant code. Substitute file on image plist.
Dave Love <fx@gnu.org>
parents:
25816
diff
changeset
|
490 (setq overlays (cdr overlays))))) |
25003 | 491 |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
492 (defun image-search-load-path (file &optional path) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
493 (unless path |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
494 (setq path image-load-path)) |
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
495 (let (element found filename) |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
496 (while (and (not found) (consp path)) |
65599
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
497 (setq element (car path)) |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
498 (cond |
65599
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
499 ((stringp element) |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
500 (setq found |
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
501 (file-readable-p |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
502 (setq filename (expand-file-name file element))))) |
65599
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
503 ((and (symbolp element) (boundp element)) |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
504 (setq element (symbol-value element)) |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
505 (cond |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
506 ((stringp element) |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
507 (setq found |
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
508 (file-readable-p |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
509 (setq filename (expand-file-name file element))))) |
65599
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
510 ((consp element) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
511 (if (setq filename (image-search-load-path file element)) |
65599
39114a2ae201
(image-load-path): Use symbol `data-directory' instead of its value,
Chong Yidong <cyd@stupidchicken.com>
parents:
65544
diff
changeset
|
512 (setq found t)))))) |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
513 (setq path (cdr path))) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
514 (if found filename))) |
25003 | 515 |
516 ;;;###autoload | |
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
517 (defun find-image (specs) |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
518 "Find an image, choosing one of a list of image specifications. |
25003 | 519 |
29470
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
520 SPECS is a list of image specifications. |
25003 | 521 |
522 Each image specification in SPECS is a property list. The contents of | |
523 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
|
524 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
|
525 `: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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 satisfied. |
7bde123bed95
(find-image): Doc fix. Return nil if image not found.
Dave Love <fx@gnu.org>
parents:
28958
diff
changeset
|
531 |
66196
2e59eea25fcf
* image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents:
65599
diff
changeset
|
532 The image is looked for in `image-load-path'. |
2e59eea25fcf
* image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents:
65599
diff
changeset
|
533 |
2e59eea25fcf
* image.el (create-image, find-image): Mention max-image-size in
Chong Yidong <cyd@stupidchicken.com>
parents:
65599
diff
changeset
|
534 Image files should not be larger than specified by `max-image-size'." |
25003 | 535 (let (image) |
536 (while (and specs (null image)) | |
537 (let* ((spec (car specs)) | |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
538 (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
|
539 (data (plist-get spec :data)) |
27921
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
540 (file (plist-get spec :file)) |
ea0a2a4f20b7
(defimage): Look for image files in load-path.
Gerd Moellmann <gerd@gnu.org>
parents:
27075
diff
changeset
|
541 found) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
542 (when (image-type-available-p type) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
543 (cond ((stringp file) |
66296
941b6508462f
(image-type-header-regexps): Rename from image-type-regexps.
Kim F. Storm <storm@cua.dk>
parents:
66196
diff
changeset
|
544 (if (setq found (image-search-load-path file)) |
65544
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
545 (setq image |
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
546 (cons 'image (plist-put (copy-sequence spec) |
78d74ef1436b
2005-09-15 Chong Yidong <cyd@stupidchicken.com>
Chong Yidong <cyd@stupidchicken.com>
parents:
64762
diff
changeset
|
547 :file found))))) |
27075
893ec72bd6b1
(create-image, defimage): Don't assume image data is a
Gerd Moellmann <gerd@gnu.org>
parents:
27073
diff
changeset
|
548 ((not (null data)) |
27073
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
549 (setq image (cons 'image spec))))) |
aad0a025b1e3
(defimage): Handle specifications containing :data
Gerd Moellmann <gerd@gnu.org>
parents:
27059
diff
changeset
|
550 (setq specs (cdr specs)))) |
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
551 image)) |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
552 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
553 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
554 ;;;###autoload |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
555 (defmacro defimage (symbol specs &optional doc) |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
556 "Define SYMBOL as an image. |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
557 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
558 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
|
559 documentation string. |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
560 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
561 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
|
562 a specification are image type dependent. All specifications must at |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
563 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
|
564 `: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
|
565 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
|
566 string containing the actual image data. The first image |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
567 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
|
568 define SYMBOL. |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
569 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
570 Example: |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
571 |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
572 (defimage test-image ((:type xpm :file \"~/test1.xpm\") |
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
573 (:type xbm :file \"~/test1.xbm\")))" |
66402
ade0d81f63a9
(defimage): Add `doc-string' declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66307
diff
changeset
|
574 (declare (doc-string 3)) |
28721
b4ea18c92e38
(find-image): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
27921
diff
changeset
|
575 `(defvar ,symbol (find-image ',specs) ,doc)) |
25003 | 576 |
577 | |
578 (provide 'image) | |
579 | |
66402
ade0d81f63a9
(defimage): Add `doc-string' declaration.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
66307
diff
changeset
|
580 ;; arch-tag: 8e76a07b-eb48-4f3e-a7a0-1a7ba9f096b3 |
25872 | 581 ;;; image.el ends here |