diff options
Diffstat (limited to 'lisp/image.el')
| -rw-r--r-- | lisp/image.el | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/lisp/image.el b/lisp/image.el index 0e71bd4a349..88e38186d7b 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; image.el --- image API | 1 | ;;; image.el --- image API |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998, 99, 2000, 01, 04 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Maintainer: FSF | 5 | ;; Maintainer: FSF |
| 6 | ;; Keywords: multimedia | 6 | ;; Keywords: multimedia |
| @@ -48,6 +48,17 @@ IMAGE-TYPE must be a pair (PREDICATE . TYPE). PREDICATE is called | |||
| 48 | with one argument, a string containing the image data. If PREDICATE returns | 48 | with one argument, a string containing the image data. If PREDICATE returns |
| 49 | a non-nil value, TYPE is the image's type.") | 49 | a non-nil value, TYPE is the image's type.") |
| 50 | 50 | ||
| 51 | ;;;###autoload | ||
| 52 | (defvar image-library-alist nil | ||
| 53 | "Alist of image types vs external libraries needed to display them. | ||
| 54 | |||
| 55 | Each element is a list (IMAGE-TYPE LIBRARY...), where the car is a symbol | ||
| 56 | representing a supported image type, and the rest are strings giving | ||
| 57 | alternate filenames for the corresponding external libraries to load. | ||
| 58 | They are tried in the order they appear on the list; if none of them can | ||
| 59 | be loaded, the running session of Emacs won't display the image type. | ||
| 60 | No entries are needed for pbm and xbm images; they're always supported.") | ||
| 61 | ;;;###autoload (put 'image-library-alist 'risky-local-variable t) | ||
| 51 | 62 | ||
| 52 | (defun image-jpeg-p (data) | 63 | (defun image-jpeg-p (data) |
| 53 | "Value is non-nil if DATA, a string, consists of JFIF image data. | 64 | "Value is non-nil if DATA, a string, consists of JFIF image data. |
| @@ -111,8 +122,8 @@ be determined." | |||
| 111 | (defun image-type-available-p (type) | 122 | (defun image-type-available-p (type) |
| 112 | "Value is non-nil if image type TYPE is available. | 123 | "Value is non-nil if image type TYPE is available. |
| 113 | Image types are symbols like `xbm' or `jpeg'." | 124 | Image types are symbols like `xbm' or `jpeg'." |
| 114 | (and (boundp 'image-types) (not (null (memq type image-types))))) | 125 | (and (fboundp 'init-image-library) |
| 115 | 126 | (init-image-library type image-library-alist))) | |
| 116 | 127 | ||
| 117 | ;;;###autoload | 128 | ;;;###autoload |
| 118 | (defun create-image (file-or-data &optional type data-p &rest props) | 129 | (defun create-image (file-or-data &optional type data-p &rest props) |
| @@ -176,7 +187,7 @@ means display it in the right marginal area." | |||
| 176 | 187 | ||
| 177 | 188 | ||
| 178 | ;;;###autoload | 189 | ;;;###autoload |
| 179 | (defun insert-image (image &optional string area) | 190 | (defun insert-image (image &optional string area slice) |
| 180 | "Insert IMAGE into current buffer at point. | 191 | "Insert IMAGE into current buffer at point. |
| 181 | IMAGE is displayed by inserting STRING into the current buffer | 192 | IMAGE is displayed by inserting STRING into the current buffer |
| 182 | with a `display' property whose value is the image. STRING is | 193 | with a `display' property whose value is the image. STRING is |
| @@ -184,7 +195,12 @@ defaulted if you omit it. | |||
| 184 | AREA is where to display the image. AREA nil or omitted means | 195 | AREA is where to display the image. AREA nil or omitted means |
| 185 | display it in the text area, a value of `left-margin' means | 196 | display it in the text area, a value of `left-margin' means |
| 186 | display it in the left marginal area, a value of `right-margin' | 197 | display it in the left marginal area, a value of `right-margin' |
| 187 | means display it in the right marginal area." | 198 | means display it in the right marginal area. |
| 199 | SLICE specifies slice of IMAGE to insert. SLICE nil or omitted | ||
| 200 | means insert whole image. SLICE is a list (X Y WIDTH HEIGHT) | ||
| 201 | specifying the X and Y positions and WIDTH and HEIGHT of image area | ||
| 202 | to insert. A float value 0.0 - 1.0 means relative to the width or | ||
| 203 | height of the image; integer values are taken as pixel values." | ||
| 188 | ;; Use a space as least likely to cause trouble when it's a hidden | 204 | ;; Use a space as least likely to cause trouble when it's a hidden |
| 189 | ;; character in the buffer. | 205 | ;; character in the buffer. |
| 190 | (unless string (setq string " ")) | 206 | (unless string (setq string " ")) |
| @@ -204,7 +220,40 @@ means display it in the right marginal area." | |||
| 204 | (let ((start (point))) | 220 | (let ((start (point))) |
| 205 | (insert string) | 221 | (insert string) |
| 206 | (add-text-properties start (point) | 222 | (add-text-properties start (point) |
| 207 | `(display ,image rear-nonsticky (display))))) | 223 | `(display ,(if slice |
| 224 | (list (cons 'slice slice) image) | ||
| 225 | image) rear-nonsticky (display))))) | ||
| 226 | |||
| 227 | |||
| 228 | (defun insert-sliced-image (image &optional string area rows cols) | ||
| 229 | (unless string (setq string " ")) | ||
| 230 | (unless (eq (car-safe image) 'image) | ||
| 231 | (error "Not an image: %s" image)) | ||
| 232 | (unless (or (null area) (memq area '(left-margin right-margin))) | ||
| 233 | (error "Invalid area %s" area)) | ||
| 234 | (if area | ||
| 235 | (setq image (list (list 'margin area) image)) | ||
| 236 | ;; Cons up a new spec equal but not eq to `image' so that | ||
| 237 | ;; inserting it twice in a row (adjacently) displays two copies of | ||
| 238 | ;; the image. Don't try to avoid this by looking at the display | ||
| 239 | ;; properties on either side so that we DTRT more often with | ||
| 240 | ;; cut-and-paste. (Yanking killed image text next to another copy | ||
| 241 | ;; of it loses anyway.) | ||
| 242 | (setq image (cons 'image (cdr image)))) | ||
| 243 | (let ((x 0.0) (dx (/ 1.0001 (or cols 1))) | ||
| 244 | (y 0.0) (dy (/ 1.0001 (or rows 1)))) | ||
| 245 | (while (< y 1.0) | ||
| 246 | (while (< x 1.0) | ||
| 247 | (let ((start (point))) | ||
| 248 | (insert string) | ||
| 249 | (add-text-properties start (point) | ||
| 250 | `(display ,(list (list 'slice x y dx dy) image) | ||
| 251 | rear-nonsticky (display))) | ||
| 252 | (setq x (+ x dx)))) | ||
| 253 | (setq x 0.0 | ||
| 254 | y (+ y dy)) | ||
| 255 | (insert (propertize "\n" 'line-height 0))))) | ||
| 256 | |||
| 208 | 257 | ||
| 209 | 258 | ||
| 210 | ;;;###autoload | 259 | ;;;###autoload |