Skip to content

Commit

Permalink
SVG: set default width/height if absent
Browse files Browse the repository at this point in the history
In the librsvg API calls for >=2.52, the newer API of
handle_get_intrinsic_size_in_pixels() doesn't set the default
width/height of the image if none is supplied.

In this case the viewbox attribute of the SVG file can be used to
determine the width/height.

If the viewbox attribute isn't present the image is not processed
further.

Fixes #1133
  • Loading branch information
ThomasAdam committed Dec 11, 2024
1 parent efef84c commit 826c89c
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions libs/PictureImageLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "fvwmlib.h"
#include "defaults.h"
#include "glib.h"
#include "librsvg/rsvg.h"
#include "log.h"
#include "System.h"
#include "Strings.h"
Expand Down Expand Up @@ -289,18 +291,32 @@ Bool PImageLoadSvg(FIMAGE_CMD_ARGS)
/* Keep the original aspect ratio when either w or h is 0 */
#if LIBRSVG_CHECK_VERSION(2,52,0)
double ddw, ddh;
gboolean has_out_w, has_out_h, has_vb;
RsvgLength out_w, out_h;
RsvgRectangle viewbox;

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);
rsvg_handle_get_intrinsic_dimensions(rsvg, &has_out_w, &out_w,
&has_out_h, &out_h, &has_vb, &viewbox);

if (!has_vb) {
fvwm_debug(__func__, "Couldn't determine viewbox");
return False;
}

dim.width = viewbox.width;
dim.height = viewbox.height;

dim.em = out_w.length;
dim.ex = out_h.length;
if (has_out_w)
dim.em = out_w.length <= dim.width ? dim.width : out_w.length;
if (has_out_h)
dim.ex = out_h.length <= dim.height ? dim.height : out_h.length;

fvwm_debug(__func__, "FINAL: DIM.EM: %f, DIM.EX: %f", dim.em, dim.ex);
#else
Frsvg_handle_get_dimensions(rsvg, &dim);
#endif
Expand Down Expand Up @@ -338,6 +354,7 @@ Bool PImageLoadSvg(FIMAGE_CMD_ARGS)
angle += 90;
}

fvwm_debug(__func__, "SIZE: %ld", w * h * sizeof(CARD32));
data = fxcalloc(1, w * h * sizeof(CARD32));
surface = Fcairo_image_surface_create_for_data((unsigned char *)data,
FCAIRO_FORMAT_ARGB32, w, h, w * sizeof(CARD32));
Expand Down

0 comments on commit 826c89c

Please sign in to comment.