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

From: Manuel Giraud <[email-masked]>
Date: Tue, 13 Dec 2022 10:21:47 +0100

Eli Zaretskii <[email-masked]> writes:

[...]

> If this fixes the issue, I'm okay with installing this on the release
> branch, but please make sure RSVG_UNIT_PERCENT was indeed introduced
> in librsvg 2.46.0, and if it was introduced later, please add a
> necessary LIBRSVG_CHECK_VERSION guard.

Hi,

Here is yet another version that is longer but I think is more correct.
The previous patch fixes a percentage dimension as a percentage of
"font_size".  This works for our case here but might not always be
correct.

This new patch calculate the unknown percentage dimension with the other
known dimension.  It should work the same on our examples (maybe Stephen
you could check that).

>From e2d827b02b0ca9f383d44a1cc51fc2aacdcae2df Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Tue, 13 Dec 2022 10:10:03 +0100
Subject: [PATCH] Fix SVG scaling (bug#59802)

Fix SVG scaling with librsvg>2.52 and SVG file with only one known
dimension.

* src/image.c (svg_load_image): Compute a percentage dimension with
the other known dimension.
---
 src/image.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/image.c b/src/image.c
index 2436f78ac3..a084143c41 100644
--- a/src/image.c
+++ b/src/image.c
@@ -11332,13 +11332,31 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
 
       if (! (0 < viewbox_width && 0 < 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,
-					      &out_logical_rect, NULL);
-	  viewbox_width = viewbox.x + viewbox.width;
-	  viewbox_height = viewbox.y + viewbox.height;
+	  /* From the previous calculation, maybe one dimension is
+	     zero and in percent unit.  So calculate this dimension
+	     with the other.  */
+	  if (! (0 < viewbox_width) && (iwidth.unit == RSVG_UNIT_PERCENT) &&
+	      has_height && (0 < viewbox_height))
+	    {
+	      viewbox_width = (viewbox_height * viewbox.width / viewbox.height)
+		* iwidth.length;
+	    }
+	  else if (! (0 < viewbox_height) && (iheight.unit == RSVG_UNIT_PERCENT) &&
+		   has_width && (0 < viewbox_width))
+	    {
+	      viewbox_height = (viewbox_width * viewbox.height / viewbox.width)
+		* iheight.length;
+	    }
+	  else
+	    {
+	      /* 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,
+						  &out_logical_rect, NULL);
+	      viewbox_width = viewbox.x + viewbox.width;
+	      viewbox_height = viewbox.y + viewbox.height;
+	    }
 	}
     }
 #else
-- 
2.38.1

-- 
Manuel Giraud