diff options
| author | Kim F. Storm | 2004-04-20 22:23:08 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2004-04-20 22:23:08 +0000 |
| commit | 5af275e049dbf787ca81aa3fdb2fea2a5ae08388 (patch) | |
| tree | 7531ed6a7020c35659b16b4661d6b1afb6c2bab2 | |
| parent | c7b08a9de6a9906101148912aeefb394e0fd37d1 (diff) | |
| download | emacs-5af275e049dbf787ca81aa3fdb2fea2a5ae08388.tar.gz emacs-5af275e049dbf787ca81aa3fdb2fea2a5ae08388.zip | |
(insert-image): Add optional SLICE arg.
(insert-sliced-image): New defun.
| -rw-r--r-- | lisp/image.el | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/lisp/image.el b/lisp/image.el index 0e71bd4a349..9d656794aa9 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -176,7 +176,7 @@ means display it in the right marginal area." | |||
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | ;;;###autoload | 178 | ;;;###autoload |
| 179 | (defun insert-image (image &optional string area) | 179 | (defun insert-image (image &optional string area slice) |
| 180 | "Insert IMAGE into current buffer at point. | 180 | "Insert IMAGE into current buffer at point. |
| 181 | IMAGE is displayed by inserting STRING into the current buffer | 181 | IMAGE is displayed by inserting STRING into the current buffer |
| 182 | with a `display' property whose value is the image. STRING is | 182 | with a `display' property whose value is the image. STRING is |
| @@ -184,7 +184,12 @@ defaulted if you omit it. | |||
| 184 | AREA is where to display the image. AREA nil or omitted means | 184 | 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 | 185 | 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' | 186 | display it in the left marginal area, a value of `right-margin' |
| 187 | means display it in the right marginal area." | 187 | means display it in the right marginal area. |
| 188 | SLICE specifies slice of IMAGE to insert. SLICE nil or omitted | ||
| 189 | means insert whole image. SLICE is a list (X Y WIDTH HEIGHT) | ||
| 190 | specifying the X and Y positions and WIDTH and HEIGHT of image area | ||
| 191 | to insert. A float value 0.0 - 1.0 means relative to the width or | ||
| 192 | 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 | 193 | ;; Use a space as least likely to cause trouble when it's a hidden |
| 189 | ;; character in the buffer. | 194 | ;; character in the buffer. |
| 190 | (unless string (setq string " ")) | 195 | (unless string (setq string " ")) |
| @@ -204,7 +209,40 @@ means display it in the right marginal area." | |||
| 204 | (let ((start (point))) | 209 | (let ((start (point))) |
| 205 | (insert string) | 210 | (insert string) |
| 206 | (add-text-properties start (point) | 211 | (add-text-properties start (point) |
| 207 | `(display ,image rear-nonsticky (display))))) | 212 | `(display ,(if slice |
| 213 | (list (cons 'slice slice) image) | ||
| 214 | image) rear-nonsticky (display))))) | ||
| 215 | |||
| 216 | |||
| 217 | (defun insert-sliced-image (image &optional string area rows cols) | ||
| 218 | (unless string (setq string " ")) | ||
| 219 | (unless (eq (car-safe image) 'image) | ||
| 220 | (error "Not an image: %s" image)) | ||
| 221 | (unless (or (null area) (memq area '(left-margin right-margin))) | ||
| 222 | (error "Invalid area %s" area)) | ||
| 223 | (if area | ||
| 224 | (setq image (list (list 'margin area) image)) | ||
| 225 | ;; Cons up a new spec equal but not eq to `image' so that | ||
| 226 | ;; inserting it twice in a row (adjacently) displays two copies of | ||
| 227 | ;; the image. Don't try to avoid this by looking at the display | ||
| 228 | ;; properties on either side so that we DTRT more often with | ||
| 229 | ;; cut-and-paste. (Yanking killed image text next to another copy | ||
| 230 | ;; of it loses anyway.) | ||
| 231 | (setq image (cons 'image (cdr image)))) | ||
| 232 | (let ((x 0.0) (dx (/ 1.0001 (or cols 1))) | ||
| 233 | (y 0.0) (dy (/ 1.0001 (or rows 1)))) | ||
| 234 | (while (< y 1.0) | ||
| 235 | (while (< x 1.0) | ||
| 236 | (let ((start (point))) | ||
| 237 | (insert string) | ||
| 238 | (add-text-properties start (point) | ||
| 239 | `(display ,(list (list 'slice x y dx dy) image) | ||
| 240 | rear-nonsticky (display))) | ||
| 241 | (setq x (+ x dx)))) | ||
| 242 | (setq x 0.0 | ||
| 243 | y (+ y dy)) | ||
| 244 | (insert "\n")))) | ||
| 245 | |||
| 208 | 246 | ||
| 209 | 247 | ||
| 210 | ;;;###autoload | 248 | ;;;###autoload |