Subject: Re: bug#64908: 29.1; svg parse failure

From: David Ponce <[email-masked]>
Date: Fri, 4 Aug 2023 23:08:14 +0200

On 04/08/2023 21:08, Eli Zaretskii wrote:
>> Date: Fri, 4 Aug 2023 19:32:13 +0100
>> From: Alan Third <[email-masked]>
>> Cc: David Ponce <[email-masked]>, [email-masked]
>>
>> On Fri, Aug 04, 2023 at 01:26:45PM +0300, Eli Zaretskii wrote:
>>>
>>> Thanks.  I hope this will help an SVG expert to figure out what's
>>> going on with these images.
>>>
>>> Alan, do you have time to look into this, per chance?
>>
>> Yeah. I know roughly what needs to be done here thanks to David's most
>> recent email, but I'll have a wee think about how best to do it since
>> we already have, I think, three different methods of finding the image
>> size depending on the version of librsvg. If I can merge a couple of
>> those approaches it will probably be best.
> 
> Thanks in advance.

Eli, Alan,

Until Alan finds the best solution, the attached simple patch fixed
the issue for me with librsvg 2.56.3.

Thanks & Regards

diff --git a/src/image.c b/src/image.c
index cb9725892d1..5abdcf710d1 100644
--- a/src/image.c
+++ b/src/image.c
@@ -11356,6 +11356,16 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
 					    &has_height, &iheight,
 					    &has_viewbox, &viewbox);
 
+# if LIBRSVG_CHECK_VERSION (2, 54, 0)
+      if (has_viewbox && has_width && has_height
+	  && (iwidth.length == 1) && (iwidth.unit == RSVG_UNIT_PERCENT)
+	  && (iwidth.length == 1) && (iheight.unit == RSVG_UNIT_PERCENT))
+	{
+	  viewbox_width = viewbox.width;
+	  viewbox_height = viewbox.height;
+	}
+      else
+# endif
       if (has_width && has_height)
 	{
 	  /* Success!  We can use these values directly.  */