Subject: bug#59802: 30.0.50; Checkbox button not rendered

From: Manuel Giraud <[email-masked]>
Date: Mon, 12 Dec 2022 13:33:46 +0100

Hi Eli and Stephen,

I tried to understand the different librsvg APIs (which is quite a mess)
and AFAIU, rsvg_handle_get_geometry_for_layer use a viewport as input to
render the SVG.  See, here:
https://gnome.pages.gitlab.gnome.org/librsvg/Rsvg-2.0/method.Handle.get_geometry_for_layer.html

So in the case we have already read a viewbox, I'm using it as the
viewport rectangle.  I don't know if it is the best way but at least it
works for me (i.e the image does not disappear below the baseline)

>From 3531a0e8515bc7499fa1e1f123b46841c7f2e9fc Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Mon, 12 Dec 2022 11:56:25 +0100
Subject: [PATCH] Fix SVG scaling for certain files with librsvg > 2.52
 (bug#59802)

* src/image.c (svg_load_image): Initialize viewport before calling
rsvg_handle_get_geometry_for_layer.
---
 src/image.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/image.c b/src/image.c
index 2436f78ac3..7db6c9d2fc 100644
--- a/src/image.c
+++ b/src/image.c
@@ -11290,7 +11290,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
     }
   else
     {
-      RsvgRectangle zero_rect, viewbox, out_logical_rect;
+      RsvgRectangle viewport, viewbox, out_logical_rect;
 
       /* Try the intrinsic dimensions first.  */
       gboolean has_width, has_height;
@@ -11332,10 +11332,19 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
 
       if (! (0 < viewbox_width && 0 < viewbox_height))
 	{
+	  /* Computed viewbox sizes are not correct but we may have
+	     read a correct viewbox so use it as the viewport.  */
+	  if (has_viewbox) {
+	    viewport.x = viewbox.x;
+	    viewport.y = viewbox.y;
+	    viewport.width = viewbox.width;
+	    viewport.height = viewbox.height;
+	  }
+
 	  /* We haven't found a usable set of sizes, so try working out
 	     the visible area.  */
 	  rsvg_handle_get_geometry_for_layer (rsvg_handle, NULL,
-					      &zero_rect, &viewbox,
+					      &viewport, &viewbox,
 					      &out_logical_rect, NULL);
 	  viewbox_width = viewbox.x + viewbox.width;
 	  viewbox_height = viewbox.y + viewbox.height;
-- 
2.38.1

-- 
Manuel Giraud