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