From a3bf934ad872999d0e63f0757429621b4e4b082c Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Wed, 6 Mar 2024 00:16:24 -0800 Subject: [PATCH] Scale image :map property according to image :scale * lisp/image.el (image--scale-map): Add function to scale an image map. (image--change-size): Use image--scale-map internally. --- lisp/image.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lisp/image.el b/lisp/image.el index 2ebce59a98c..48c38a0c9ec 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -1269,7 +1269,28 @@ image--change-size (new-image (image--image-without-parameters image)) (scale (image--current-scaling image new-image))) (setcdr image (cdr new-image)) - (plist-put (cdr image) :scale (* scale factor)))) + (plist-put (cdr image) :scale (* scale factor)) + (setf (image-property new-image :map) + (image--scale-map (image-property new-image :map) factor)))) + +(defun image--scale-map (map factor) + "Scale MAP by FACTOR, destructively modifying it." + (pcase-dolist (`(,`(,type . ,coords) ,id ,plist) map) + (pcase-exhaustive type + ('rect + (setf (caar coords) (round (* (caar coords) factor))) + (setf (cdar coords) (round (* (cdar coords) factor))) + (setf (cadr coords) (round (* (cadr coords) factor))) + (setf (cddr coords) (round (* (cddr coords) factor)))) + ('circle + (setf (caar coords) (round (* (caar coords) factor))) + (setf (cdar coords) (round (* (cdar coords) factor))) + (setf (cdr coords) (round (* (cdr coords) factor)))) + ('poly + (dotimes (i (length coords)) + (aset coords i + (round (* (aref coords i) factor))))))) + map) (defun image--image-without-parameters (image) (cons (pop image) -- 2.41.0