From 3531a0e8515bc7499fa1e1f123b46841c7f2e9fc Mon Sep 17 00:00:00 2001 From: Manuel Giraud 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