ptrdiff_t size, char *filename)
{
RsvgHandle *rsvg_handle;
- RsvgDimensionData dimension_data;
+ double viewbox_width, viewbox_height;
GError *err = NULL;
GdkPixbuf *pixbuf;
int width;
#endif
/* Get the image dimensions. */
+#if LIBRSVG_CHECK_VERSION (2, 46, 0)
+ RsvgRectangle zero_rect, viewbox;
+
+ rsvg_handle_get_geometry_for_layer (rsvg_handle, NULL,
+ &zero_rect, &viewbox,
+ NULL, NULL);
+ 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;
+#endif
+ compute_image_size (viewbox_width, viewbox_height, img->spec,
+ &width, &height);
+
+ if (! check_image_size (f, width, height))
+ {
+ image_size_error ();
+ goto rsvg_error;
+ }
+
/* We are now done with the unmodified data. */
g_object_unref (rsvg_handle);
- /* Calculate the final image size. */
- compute_image_size (dimension_data.width, dimension_data.height,
- img->spec, &width, &height);
-
/* Wrap the SVG data in another SVG. This allows us to set the
width and height, as well as modify the foreground and background
colors. */
"xmlns:xi=\"http://www.w3.org/2001/XInclude\" "
"style=\"color: #%06X; fill: currentColor;\" "
"width=\"%d\" height=\"%d\" preserveAspectRatio=\"none\" "
- "viewBox=\"0 0 %d %d\">"
+ "viewBox=\"0 0 %f %f\">"
"<rect width=\"100%%\" height=\"100%%\" fill=\"#%06X\"/>"
"<xi:include href=\"data:image/svg+xml;base64,%s\"></xi:include>"
"</svg>";
if (!wrapped_contents
|| buffer_size <= snprintf (wrapped_contents, buffer_size, wrapper,
foreground & 0xFFFFFF, width, height,
- dimension_data.width, dimension_data.height,
- background & 0xFFFFFF, SSDATA (encoded_contents)))
+ viewbox_width, viewbox_height,
+ background & 0xFFFFFF,
+ SSDATA (encoded_contents)))
goto rsvg_error;
wrapped_size = strlen (wrapped_contents);
if (err) goto rsvg_error;
#endif
- rsvg_handle_get_dimensions (rsvg_handle, &dimension_data);
- if (! check_image_size (f, dimension_data.width, dimension_data.height))
- {
- image_size_error ();
- goto rsvg_error;
- }
/* We can now get a valid pixel buffer from the svg file, if all
went ok. */