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

SVG: set default width/height if absent #1135

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading