From 4feeb7570df33ac335049296d62dba5e05031747 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 26 Sep 2022 13:53:10 +0200 Subject: [PATCH] Rescale images along with text in eww with `C-x C-+' * lisp/net/eww.el (eww--rescale-images): Also rescale images when using `C-x C-+' etc (bug#58047). --- lisp/net/eww.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index af938e3c192..2a511333de1 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1179,8 +1179,28 @@ the like." (setq-local bookmark-make-record-function #'eww-bookmark-make-record) (buffer-disable-undo) (setq-local shr-url-transformer #'eww--transform-url) + ;; Also rescale images when rescaling the text. + (add-hook 'text-scale-mode-hook #'eww--rescale-images nil t) (setq buffer-read-only t)) +(defvar text-scale-mode) +(defvar text-scale-mode-amount) +(defun eww--rescale-images () + (let ((scaling (if text-scale-mode + (+ 1 (* text-scale-mode-amount 0.1)) + 1)) + match) + (save-excursion + (goto-char (point-min)) + (while (setq match (text-property-search-forward 'display)) + (let ((image (prop-match-value match))) + (when (imagep image) + (unless (image-property image :original-scale) + (setf (image-property image :original-scale) + (or (image-property image :scale) 1))) + (setf (image-property image :scale) + (* (image-property image :original-scale) scaling)))))))) + (defun eww--url-at-point () "`thing-at-point' provider function." (get-text-property (point) 'shr-url)) -- 2.39.2