diff options
| author | Shyam Karanatt | 2010-07-17 17:51:04 -0400 |
|---|---|---|
| committer | Chong Yidong | 2010-07-17 17:51:04 -0400 |
| commit | c9088194ea32fafd6371a33e63c45bcc15cbb8aa (patch) | |
| tree | aa83454f5db418a0dcde32b12998ab2dc613d78a | |
| parent | dad7c7162bddfad0aa60648042f9a7f0d1255ee5 (diff) | |
| download | emacs-c9088194ea32fafd6371a33e63c45bcc15cbb8aa.tar.gz emacs-c9088194ea32fafd6371a33e63c45bcc15cbb8aa.zip | |
Fix size calculation for sliced images in image-mode (Bug#6639).
* lisp/image-mode.el (image-display-size): New function.
(image-forward-hscroll, image-next-line, image-eol, image-eob)
(image-mode-fit-frame): Use it (Bug#6639).
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/image-mode.el | 34 |
2 files changed, 34 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2ce2201f34b..b0dbe931e9f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2010-07-17 Shyam Karanatt <shyam@swathanthran.in> (tiny change) | ||
| 2 | |||
| 3 | * image-mode.el (image-display-size): New function. | ||
| 4 | (image-forward-hscroll, image-next-line, image-eol, image-eob) | ||
| 5 | (image-mode-fit-frame): Use it (Bug#6639). | ||
| 6 | |||
| 1 | 2010-07-17 Chong Yidong <cyd@stupidchicken.com> | 7 | 2010-07-17 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 8 | ||
| 3 | * dired.el (dired-buffers-for-dir): Handle list values of | 9 | * dired.el (dired-buffers-for-dir): Handle list values of |
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index a9736541a4f..7143d9833c0 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -128,6 +128,28 @@ A winprops object has the shape (WINDOW . ALIST)." | |||
| 128 | 128 | ||
| 129 | (declare-function image-size "image.c" (spec &optional pixels frame)) | 129 | (declare-function image-size "image.c" (spec &optional pixels frame)) |
| 130 | 130 | ||
| 131 | (defun image-display-size (spec &optional pixels frame) | ||
| 132 | "Wrapper around `image-size', to handle slice display properties. | ||
| 133 | If SPEC is an image display property, call `image-size' with the | ||
| 134 | given arguments. | ||
| 135 | If SPEC is a list of properties containing `image' and `slice' | ||
| 136 | properties, calculate the display size from the slice property. | ||
| 137 | If SPEC contains `image' but not `slice', call `image-size' with | ||
| 138 | the specified image." | ||
| 139 | (if (eq (car spec) 'image) | ||
| 140 | (image-size spec pixels frame) | ||
| 141 | (let ((image (assoc 'image spec)) | ||
| 142 | (slice (assoc 'slice spec))) | ||
| 143 | (cond ((and image slice) | ||
| 144 | (if pixels | ||
| 145 | (cons (nth 3 slice) (nth 4 slice)) | ||
| 146 | (cons (/ (float (nth 3 slice)) (frame-char-width frame)) | ||
| 147 | (/ (float (nth 4 slice)) (frame-char-height frame))))) | ||
| 148 | (image | ||
| 149 | (image-size image pixels frame)) | ||
| 150 | (t | ||
| 151 | (error "Invalid image specification: %s" spec)))))) | ||
| 152 | |||
| 131 | (defun image-forward-hscroll (&optional n) | 153 | (defun image-forward-hscroll (&optional n) |
| 132 | "Scroll image in current window to the left by N character widths. | 154 | "Scroll image in current window to the left by N character widths. |
| 133 | Stop if the right edge of the image is reached." | 155 | Stop if the right edge of the image is reached." |
| @@ -139,7 +161,7 @@ Stop if the right edge of the image is reached." | |||
| 139 | (let* ((image (image-get-display-property)) | 161 | (let* ((image (image-get-display-property)) |
| 140 | (edges (window-inside-edges)) | 162 | (edges (window-inside-edges)) |
| 141 | (win-width (- (nth 2 edges) (nth 0 edges))) | 163 | (win-width (- (nth 2 edges) (nth 0 edges))) |
| 142 | (img-width (ceiling (car (image-size image))))) | 164 | (img-width (ceiling (car (image-display-size image))))) |
| 143 | (image-set-window-hscroll (min (max 0 (- img-width win-width)) | 165 | (image-set-window-hscroll (min (max 0 (- img-width win-width)) |
| 144 | (+ n (window-hscroll)))))))) | 166 | (+ n (window-hscroll)))))))) |
| 145 | 167 | ||
| @@ -160,7 +182,7 @@ Stop if the bottom edge of the image is reached." | |||
| 160 | (let* ((image (image-get-display-property)) | 182 | (let* ((image (image-get-display-property)) |
| 161 | (edges (window-inside-edges)) | 183 | (edges (window-inside-edges)) |
| 162 | (win-height (- (nth 3 edges) (nth 1 edges))) | 184 | (win-height (- (nth 3 edges) (nth 1 edges))) |
| 163 | (img-height (ceiling (cdr (image-size image))))) | 185 | (img-height (ceiling (cdr (image-display-size image))))) |
| 164 | (image-set-window-vscroll (min (max 0 (- img-height win-height)) | 186 | (image-set-window-vscroll (min (max 0 (- img-height win-height)) |
| 165 | (+ n (window-vscroll)))))))) | 187 | (+ n (window-vscroll)))))))) |
| 166 | 188 | ||
| @@ -233,7 +255,7 @@ stopping if the top or bottom edge of the image is reached." | |||
| 233 | (let* ((image (image-get-display-property)) | 255 | (let* ((image (image-get-display-property)) |
| 234 | (edges (window-inside-edges)) | 256 | (edges (window-inside-edges)) |
| 235 | (win-width (- (nth 2 edges) (nth 0 edges))) | 257 | (win-width (- (nth 2 edges) (nth 0 edges))) |
| 236 | (img-width (ceiling (car (image-size image))))) | 258 | (img-width (ceiling (car (image-display-size image))))) |
| 237 | (image-set-window-hscroll (max 0 (- img-width win-width))))) | 259 | (image-set-window-hscroll (max 0 (- img-width win-width))))) |
| 238 | 260 | ||
| 239 | (defun image-bob () | 261 | (defun image-bob () |
| @@ -248,9 +270,9 @@ stopping if the top or bottom edge of the image is reached." | |||
| 248 | (let* ((image (image-get-display-property)) | 270 | (let* ((image (image-get-display-property)) |
| 249 | (edges (window-inside-edges)) | 271 | (edges (window-inside-edges)) |
| 250 | (win-width (- (nth 2 edges) (nth 0 edges))) | 272 | (win-width (- (nth 2 edges) (nth 0 edges))) |
| 251 | (img-width (ceiling (car (image-size image)))) | 273 | (img-width (ceiling (car (image-display-size image)))) |
| 252 | (win-height (- (nth 3 edges) (nth 1 edges))) | 274 | (win-height (- (nth 3 edges) (nth 1 edges))) |
| 253 | (img-height (ceiling (cdr (image-size image))))) | 275 | (img-height (ceiling (cdr (image-display-size image))))) |
| 254 | (image-set-window-hscroll (max 0 (- img-width win-width))) | 276 | (image-set-window-hscroll (max 0 (- img-width win-width))) |
| 255 | (image-set-window-vscroll (max 0 (- img-height win-height))))) | 277 | (image-set-window-vscroll (max 0 (- img-height win-height))))) |
| 256 | 278 | ||
| @@ -264,7 +286,7 @@ This function assumes the current frame has only one window." | |||
| 264 | (interactive) | 286 | (interactive) |
| 265 | (let* ((saved (frame-parameter nil 'image-mode-saved-size)) | 287 | (let* ((saved (frame-parameter nil 'image-mode-saved-size)) |
| 266 | (display (image-get-display-property)) | 288 | (display (image-get-display-property)) |
| 267 | (size (image-size display))) | 289 | (size (image-display-size display))) |
| 268 | (if (and saved | 290 | (if (and saved |
| 269 | (eq (caar saved) (frame-width)) | 291 | (eq (caar saved) (frame-width)) |
| 270 | (eq (cdar saved) (frame-height))) | 292 | (eq (cdar saved) (frame-height))) |