Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose: Fix SVG scaling with librsvg 2.52 #376

Merged
merged 1 commit into from Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -156,10 +156,8 @@ asc_canvas_render_svg (AscCanvas *canvas, GInputStream *stream, GError **error)
RsvgHandle *handle = NULL;
gboolean ret = FALSE;
gdouble srf_width, srf_height;
gdouble svg_width, svg_height;
#if LIBRSVG_CHECK_VERSION(2, 52, 0)
RsvgRectangle viewport;
GError *tmp_error = NULL;
#else
RsvgDimensionData dims;
#endif
@@ -181,45 +179,31 @@ asc_canvas_render_svg (AscCanvas *canvas, GInputStream *stream, GError **error)
srf_width = (gdouble) cairo_image_surface_get_width (priv->srf);
srf_height = (gdouble) cairo_image_surface_get_height (priv->srf);

#if LIBRSVG_CHECK_VERSION(2, 52, 0)
ret = rsvg_handle_get_intrinsic_size_in_pixels(handle, &svg_width, &svg_height);
if (!ret) {
/* we would need a viewport to get an intrinsic pixel size. Work around this issue
* by just scaling the SVG as high or low as we want to */
svg_width = srf_width;
svg_height = srf_height;
}
#else
rsvg_handle_get_dimensions (handle, &dims);
svg_width = dims.width;
svg_height = dims.height;
#endif

/* cairo_translate (cr, (srf_width - svg_width) / 2, (srf_height - svg_height) / 2); */
cairo_scale (priv->cr,
srf_width / svg_width,
srf_height / svg_height);

cairo_save (priv->cr);


#if LIBRSVG_CHECK_VERSION(2, 52, 0)
viewport.x = 0;
viewport.y = 0;
viewport.width = srf_width;
viewport.height = srf_height;

ret = rsvg_handle_render_document (handle,
priv->cr,
&viewport,
&tmp_error);
error);
if (!ret) {
cairo_restore (priv->cr);
g_propagate_prefixed_error (error,
tmp_error,
"SVG graphic rendering failed:");
g_prefix_error (error, "SVG graphic rendering failed:");
goto out;
}
#else
rsvg_handle_get_dimensions (handle, &dims);

/* cairo_translate (cr, (srf_width - dims.width) / 2, (srf_height - dims.height) / 2); */
cairo_scale (priv->cr,
srf_width / dims.width,
srf_height / dims.height);

ret = rsvg_handle_render_cairo (handle, priv->cr);
if (!ret) {
cairo_restore (priv->cr);