diff --git a/src/image.c b/src/image.c index cb9725892d1..ae24f5b3893 100644 --- a/src/image.c +++ b/src/image.c @@ -11358,12 +11358,16 @@ svg_load_image (struct frame *f, struct image *img, char *contents, if (has_width && has_height) { + /* Success! We can use these values directly. */ - viewbox_width = svg_css_length_to_pixels (iwidth, dpi, - img->face_font_size); - viewbox_height = svg_css_length_to_pixels (iheight, dpi, - img->face_font_size); - + viewbox_width = ((iwidth.unit == RSVG_UNIT_PERCENT) && has_viewbox) + ? viewbox.width * iwidth.length + : svg_css_length_to_pixels (iwidth, dpi, img->face_font_size); + + viewbox_height = ((iheight.unit == RSVG_UNIT_PERCENT) && has_viewbox) + ? viewbox.height * iheight.length + : svg_css_length_to_pixels (iheight, dpi, img->face_font_size); + /* Here one dimension could be zero because in percent unit. So calculate this dimension with the other. */ if (! (0 < viewbox_width) && (iwidth.unit == RSVG_UNIT_PERCENT))