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

image zoom in and out again



When doing an image zoom with M-[ and M=] I noticed that the original
image size is not restored by going "out" then back "in".  I wonder if
they could be made symmetric with something like below.

The effect is sort of fixed steps (in geometric progression) up and
down.

There could be some merit also in a "return to original size".  Unless
it's hiding somewhere I didn't see :).  What about the button-3 popup
menu an "Original size", clickable if not already original size.

2014-06-11  Kevin Ryde  <user42_kevin@xxxxxxxxxxxx>

	* w3m.el (w3m-zoom-out-image, w3m-resize-image-interactive): Treat
	zoom-out percentage as inverse of zoom-in, so "in" then "out" returns
	to the original size.
	(w3m-resize-inline-image-internal): Set w3m-image-scale property to
	flonum to avoid integer round-off when resizing in and out.  Use
	`round' rather than `truncate' when calling "convert" so flonum
	round-off 99.999 is original 100%.
--- w3m.el.~1.1617.~	2014-05-29 10:17:01.000000000 +1000
+++ w3m.el	2014-06-11 10:36:36.999313430 +1000
@@ -4106,8 +4106,9 @@
 	 (allow-non-secure-images (not w3m-confirm-leaving-secure-page))
 	 scale image)
     (w3m-add-text-properties start end '(w3m-image-status on))
-    (setq scale (truncate (* iscale rate 0.01)))
+    (setq scale (* iscale rate 0.01))
     (w3m-add-text-properties start end (list 'w3m-image-scale scale))
+    (setq scale (round scale))
     (if (get-text-property start 'w3m-image-redundant)
 	(progn
 	  ;; Insert a dummy string instead of a redundant image.
@@ -4184,10 +4185,10 @@
 	       (setq changed-rate (* changed-rate
 				     (/ percent 100.0)))))
 	    ((eq char ?-)
-	     (let ((percent (- 100 (if rate
-				       (if (> rate 99) 99
-					 rate)
-				     w3m-resize-image-scale))))
+	     (let ((percent (/ 10000.0 (+ 100 (if rate
+                                                  (if (> rate 99) 99
+                                                    rate)
+                                                w3m-resize-image-scale)))))
 	       (w3m-resize-inline-image-internal image percent)
 	       (setq changed-rate (* changed-rate
 				     (/ percent 100.0)))))
@@ -4227,9 +4228,15 @@
 
 (defun w3m-zoom-out-image (&optional rate)
   "Zoom out an image on the point.
-Numeric prefix specifies how many percent the image is shrunk by
-\(30 means shrinking the image by 70%).  The default is the value of
-the `w3m-resize-image-scale' variable."
+Numeric prefix specifies how many percent the image is shrunk by.
+The default is the value of the `w3m-resize-image-scale'
+variable.
+
+The shrink percentage is interpreted as if the current image size
+is 100+percent and it is to be reduced back to 100.  This is the
+inverse of `w3m-zoom-in-image' so zooming in then back out gives
+the original again."
+
   (interactive "P")
   (unless (w3m-display-graphic-p)
     (error "Can't display images in this environment"))
@@ -4239,7 +4246,7 @@
     (if url
 	(w3m-resize-inline-image-internal
 	 url
-	 (- 100 (or rate w3m-resize-image-scale)))
+	 (/ 10000.0 (+ 100 (or rate w3m-resize-image-scale))))
       (w3m-message "No image at point"))))
 
 (defun w3m-decode-entities (&optional keep-properties)