Subject: bug#44655: 28.0.50; Oversized SVG margin

From: Alan Third <[email-masked]>
Date: Sun, 15 Nov 2020 17:25:35 +0000

On Sun, Nov 15, 2020 at 11:59:11AM +0300, Matsievskiy S.V. wrote:
> Inserted into overlays SVG images have oversized bottom and right
> margins. This bug was
> introduced somewhere between 109eb1e7e29455418b40ca00bf5dad3e61e5fc78
> and a32fd9f64d06ccd07a9beaf6d6f1283f7a80edac

This is exactly what I expected when I made the last change: someone
would quickly find an SVG that doesn't work.

All I can think of to do is ignore the deprecation of
svg_handle_get_dimensions and continue using it. The release notes for
librsvg 2.46 state it's deprecated but still available.

Patch attached. Are we happy to continue using deprecated functions?

(I was looking through the librsvg bug tracker and it looks as though
they want to move away from depending on Cairo. Perhaps this means
things will improve for us in the future.)
-- 
Alan Third
>From 2408b2579ee9fbe831035b7784133863d91b77ab Mon Sep 17 00:00:00 2001
From: Alan Third <[email-masked]>
Date: Sun, 15 Nov 2020 17:21:03 +0000
Subject: [PATCH] Fix SVG display again (bug#44655)

* src/image.c (svg_load_image): Fall back to a deprecated function if
we can't calculate the size of the image.
---
 src/image.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/src/image.c b/src/image.c
index 3858f3c41f..652605d9c8 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9903,27 +9903,34 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
       viewbox_width = viewbox.x + viewbox.width;
       viewbox_height = viewbox.y + viewbox.height;
     }
-#else
-  /* The function used above to get the geometry of the visible area
-     of the SVG are only available in librsvg 2.46 and above, so in
-     certain circumstances this code path can result in some parts of
-     the SVG being cropped.  */
-  RsvgDimensionData dimension_data;
-
-  rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
 
-  viewbox_width = dimension_data.width;
-  viewbox_height = dimension_data.height;
+  if (viewbox_width == 0 || viewbox_height == 0)
 #endif
+  {
+    /* The functions used above to get the geometry of the visible
+       area of the SVG are only available in librsvg 2.46 and above,
+       so in certain circumstances this code path can result in some
+       parts of the SVG being cropped.
+
+       FIXME: The rsvg_handle_get_dimensions has been deprecated since
+       version 2.46 of librsvg, but is still available.  With some SVG
+       files (bug#44655) I can't find any other way to get sensible
+       dimensions from librsvg, so with 2.46 and above this is a last
+       ditch attempt.  Presumably at some point the function will be
+       removed and this will need to be changed.  */
+    RsvgDimensionData dimension_data;
+
+    rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
+
+    viewbox_width = dimension_data.width;
+    viewbox_height = dimension_data.height;
+  }
 
   if (viewbox_width == 0 || viewbox_height == 0)
     {
       /* We do not have any usable dimensions, so make some up.  The
          values below are supposedly the default values most web
          browsers use for SVGs with no set size.  */
-      /* FIXME: At this stage we should perhaps consider rendering the
-         image out to a bitmap and getting the dimensions from
-         that.  */
       viewbox_width = 300;
       viewbox_height = 150;
     }
-- 
2.26.1