Subject: bug#71913: 29.1; shr: shr-resize-image does not behave as expected

From: Jim Porter <[email-masked]>
Date: Thu, 11 Jul 2024 16:51:53 -0700

On 7/10/2024 12:02 PM, George Huebner wrote:
> As I understand it, this decision was likely made because the dimensions 
> of SVGs is weird; they aren't inherently required to have a size, but 
> the SVG itself can define a viewbox with accompanying width and height 
> (full disclosure: I have no idea what I'm talking about).

I think this was just a mistake. I tried getting rid of the special case 
for SVG and everything works just fine in builds with or without SVG 
support. (In builds without SVG support, you just get the empty string 
where an SVG would be, before and after this patch.)

From 70ecc19f735e0cea0fda8721d7f2709c39f1bbff Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Thu, 11 Jul 2024 16:29:37 -0700
Subject: [PATCH] Treat SVG images like other image types in 'shr-put-image'

For both SVG and no-SVG builds, this works as expected (in the no-SVG
case, it would raise an error which subsequently gets ignored).
However, compared to the previous implementation, this lets users resize
SVG images just like every other image type.

* lisp/net/shr.el (shr-put-image): Don't special-case SVGs.
---
 lisp/net/shr.el | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 39271cc5296..d3c48b34428 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1193,23 +1193,18 @@ shr-put-image
   (if (display-graphic-p)
       (let* ((zoom (or (plist-get flags :zoom)
                        (car shr-image-zoom-levels)))
-             (zoom-function (nth 2 (assq zoom shr-image-zoom-level-alist)))
+             (zoom-function (or (nth 2 (assq zoom shr-image-zoom-level-alist))
+                                (error "Unrecognized zoom level %s" zoom)))
 	     (data (if (consp spec)
 		       (car spec)
 		     spec))
 	     (content-type (and (consp spec)
 				(cadr spec)))
 	     (start (point))
-	     (image (cond
-		     ((eq content-type 'image/svg+xml)
-                      (when (image-type-available-p 'svg)
-		        (create-image data 'svg t :ascent shr-image-ascent)))
-                     (zoom-function
-                      (ignore-errors
-                        (funcall zoom-function data content-type
-                                 (plist-get flags :width)
-                                 (plist-get flags :height))))
-                     (t (error "Unrecognized zoom level %s" zoom)))))
+	     (image (ignore-errors
+                      (funcall zoom-function data content-type
+                               (plist-get flags :width)
+                               (plist-get flags :height)))))
         (when image
           ;; The trailing space can confuse shr-insert into not
           ;; putting any space after inline images.
-- 
2.25.1