emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-23 r99932: Fix size calculation for s


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-23 r99932: Fix size calculation for sliced images in image-mode (Bug#6639).
Date: Sat, 17 Jul 2010 17:51:04 -0400
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 99932
author: Shyam Karanatt <address@hidden>
committer: Chong Yidong <address@hidden>
branch nick: emacs-23
timestamp: Sat 2010-07-17 17:51:04 -0400
message:
  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).
modified:
  lisp/ChangeLog
  lisp/image-mode.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-07-17 21:25:32 +0000
+++ b/lisp/ChangeLog    2010-07-17 21:51:04 +0000
@@ -1,3 +1,9 @@
+2010-07-17  Shyam Karanatt  <address@hidden>  (tiny change)
+
+       * 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).
+
 2010-07-17  Chong Yidong  <address@hidden>
 
        * dired.el (dired-buffers-for-dir): Handle list values of

=== modified file 'lisp/image-mode.el'
--- a/lisp/image-mode.el        2010-04-23 16:35:57 +0000
+++ b/lisp/image-mode.el        2010-07-17 21:51:04 +0000
@@ -128,6 +128,28 @@
 
 (declare-function image-size "image.c" (spec &optional pixels frame))
 
+(defun image-display-size (spec &optional pixels frame)
+  "Wrapper around `image-size', to handle slice display properties.
+If SPEC is an image display property, call `image-size' with the
+given arguments.
+If SPEC is a list of properties containing `image' and `slice'
+properties, calculate the display size from the slice property.
+If SPEC contains `image' but not `slice', call `image-size' with
+the specified image."
+  (if (eq (car spec) 'image)
+      (image-size spec pixels frame)
+    (let ((image (assoc 'image spec))
+         (slice (assoc 'slice spec)))
+      (cond ((and image slice)
+            (if pixels
+                (cons (nth 3 slice) (nth 4 slice))
+              (cons (/ (float (nth 3 slice)) (frame-char-width frame))
+                    (/ (float (nth 4 slice)) (frame-char-height frame)))))
+           (image
+            (image-size image pixels frame))
+           (t
+            (error "Invalid image specification: %s" spec))))))
+
 (defun image-forward-hscroll (&optional n)
   "Scroll image in current window to the left by N character widths.
 Stop if the right edge of the image is reached."
@@ -139,7 +161,7 @@
         (let* ((image (image-get-display-property))
                (edges (window-inside-edges))
                (win-width (- (nth 2 edges) (nth 0 edges)))
-               (img-width (ceiling (car (image-size image)))))
+               (img-width (ceiling (car (image-display-size image)))))
           (image-set-window-hscroll (min (max 0 (- img-width win-width))
                                          (+ n (window-hscroll))))))))
 
@@ -160,7 +182,7 @@
         (let* ((image (image-get-display-property))
                (edges (window-inside-edges))
                (win-height (- (nth 3 edges) (nth 1 edges)))
-               (img-height (ceiling (cdr (image-size image)))))
+               (img-height (ceiling (cdr (image-display-size image)))))
           (image-set-window-vscroll (min (max 0 (- img-height win-height))
                                          (+ n (window-vscroll))))))))
 
@@ -233,7 +255,7 @@
   (let* ((image (image-get-display-property))
         (edges (window-inside-edges))
         (win-width (- (nth 2 edges) (nth 0 edges)))
-        (img-width (ceiling (car (image-size image)))))
+        (img-width (ceiling (car (image-display-size image)))))
     (image-set-window-hscroll (max 0 (- img-width win-width)))))
 
 (defun image-bob ()
@@ -248,9 +270,9 @@
   (let* ((image (image-get-display-property))
         (edges (window-inside-edges))
         (win-width (- (nth 2 edges) (nth 0 edges)))
-        (img-width (ceiling (car (image-size image))))
+        (img-width (ceiling (car (image-display-size image))))
         (win-height (- (nth 3 edges) (nth 1 edges)))
-        (img-height (ceiling (cdr (image-size image)))))
+        (img-height (ceiling (cdr (image-display-size image)))))
     (image-set-window-hscroll (max 0 (- img-width win-width)))
     (image-set-window-vscroll (max 0 (- img-height win-height)))))
 
@@ -264,7 +286,7 @@
   (interactive)
   (let* ((saved (frame-parameter nil 'image-mode-saved-size))
          (display (image-get-display-property))
-         (size (image-size display)))
+         (size (image-display-size display)))
     (if (and saved
              (eq (caar saved) (frame-width))
              (eq (cdar saved) (frame-height)))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]