imv works fine with png files. However, it doesn't position my svg files in the center of the window, but rather on in the bottom right corner, effectively showing only a quarter of the file.
Using imv 4.3.1-5 (arch linux community package) from sway r6915.a7898637-1
I have the same issue on the latest version of imv! I believe it happens when scale is not 1 on any of the outputs. When I have scale=1.4 on either of my displays and SVG files in imv are centered around 2x the coordinates of the screen center. It only works correctly when both displays have scale=1.
I've had a look at this and it seems like the issue was introduced by commit 3c1d27d8859cc4eda5802c1502ee5ae7430a9c8f in an attempt to make font sizes scale. Using the output scale directly to just set the font size works as well, without breaking SVG scaling.
I have not found anything that breaks with these changes, but it's the first time I've looked into this code base and I'm not familiar with Cairo, Wayland, and graphics programming in general.
It can be quite confusing when reading the code that
scale
can refer to either the output scale of a monitor as set by the window manager or to the factor by which an image is scaled for rendering it.diff --git a/src/canvas.c b/src/canvas.c index 1e95299..a02cef7 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -90,7 +90,7 @@ void imv_canvas_free(struct imv_canvas *canvas) free(canvas); } -void imv_canvas_resize(struct imv_canvas *canvas, int width, int height, double scale) +void imv_canvas_resize(struct imv_canvas *canvas, int width, int height) { cairo_destroy(canvas->cairo); cairo_surface_destroy(canvas->surface); @@ -101,7 +101,6 @@ void imv_canvas_resize(struct imv_canvas *canvas, int width, int height, double canvas->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, canvas->width, canvas->height); assert(canvas->surface); - cairo_surface_set_device_scale(canvas->surface, scale, scale); canvas->cairo = cairo_create(canvas->surface); assert(canvas->cairo); } diff --git a/src/canvas.h b/src/canvas.h index 4449b32..2980901 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -21,7 +21,7 @@ struct imv_canvas *imv_canvas_create(int width, int height); void imv_canvas_free(struct imv_canvas *canvas); /* Set the buffer size of the canvas */ -void imv_canvas_resize(struct imv_canvas *canvas, int width, int height, double scale); +void imv_canvas_resize(struct imv_canvas *canvas, int width, int height); /* Blank the canvas to be empty and transparent */ void imv_canvas_clear(struct imv_canvas *canvas); diff --git a/src/imv.c b/src/imv.c index ce0c43a..54a8a3f 100644 --- a/src/imv.c +++ b/src/imv.c @@ -450,7 +450,8 @@ static void event_handler(void *data, const struct imv_event *e) const int bh = e->data.resize.buffer_height; const double scale = e->data.resize.scale; imv_viewport_update(imv->view, ww, wh, bw, bh, imv->current_image, imv->scaling_mode); - imv_canvas_resize(imv->canvas, bw, bh, scale); + imv_canvas_resize(imv->canvas, bw, bh); + imv_canvas_font(imv->canvas, imv->overlay.font.name, imv->overlay.font.size * scale); break; } case IMV_EVENT_KEYBOARD: