Skip to content

Commit

Permalink
librsvg: update to newer API
Browse files Browse the repository at this point in the history
Certain calls to functions such as rsvg_handle_get_dimensions() and
rsvg_handle_render_cairo() have been deprecated since version 2.52, yet
we've not bothered to keep up to date with the changes to the API.

Change this, but keep backwards compatibility for older librsvg
installations.

Fixes #974
  • Loading branch information
ThomasAdam committed Oct 1, 2024
1 parent 917ba28 commit 29f0552
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libs/PictureImageLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,23 @@ Bool PImageLoadSvg(FIMAGE_CMD_ARGS)
free(allocated_path);

/* Keep the original aspect ratio when either w or h is 0 */
#if LIBRSVG_CHECK_VERSION(2,52,0)
double ddw, ddh;
RsvgLength out_w, out_h;

rsvg_handle_get_intrinsic_size_in_pixels(rsvg, &ddw, &ddh);
dim.width = ddw;
dim.height = ddh;

rsvg_handle_get_intrinsic_dimensions(rsvg, NULL, &out_w, NULL, &out_h,
NULL, NULL);

dim.em = out_w.length;
dim.ex = out_h.length;

#else
Frsvg_handle_get_dimensions(rsvg, &dim);
#endif
if (!w && !h)
{
w = dim.width;
Expand Down Expand Up @@ -357,7 +373,19 @@ Bool PImageLoadSvg(FIMAGE_CMD_ARGS)
Fcairo_translate(cr, -.5, -.5);
Fcairo_scale(cr, 1 / dim.em, 1 / dim.ex);

#if LIBRSVG_CHECK_VERSION(2,52,0)
GError *err = NULL;
RsvgRectangle vp;

vp.x = 0;
vp.y = 0;
vp.width = dim.width;
vp.height = dim.height;

rsvg_handle_render_document(rsvg, cr, &vp, &err);
#else
Frsvg_handle_render_cairo(rsvg, cr);
#endif
Fg_object_unref(FG_OBJECT(rsvg));
Fcairo_destroy(cr);

Expand Down

0 comments on commit 29f0552

Please sign in to comment.