From f302cf5eee5c4b9ed0b5efb8a6e95f51815e327a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20M=C3=BCller?= Date: Sun, 10 Jul 2022 17:47:33 +0200 Subject: [PATCH] GRC/Screenshots: create ImageSurface with int dimensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since cairo.ImageSurface is pixel-based, it only accepts integer dimensions. No need to round up – proper rounding and padding make this quite safe. Signed-off-by: Marcus Müller --- gui/Utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gui/Utils.py b/gui/Utils.py index 5c643c9..2629afa 100644 --- a/gui/Utils.py +++ b/gui/Utils.py @@ -108,7 +108,13 @@ def make_screenshot(flow_graph, file_path, transparent_bg=False): height = y_max - y_min + 2 * padding if file_path.endswith('.png'): - psurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + # ImageSurface is pixel-based, so dimensions need to be integers + # We don't round up here, because our padding should allow for up + # to half a pixel size in loss of image area without optically bad + # effects + psurf = cairo.ImageSurface(cairo.FORMAT_ARGB32, + round(width), + round(height)) elif file_path.endswith('.pdf'): psurf = cairo.PDFSurface(file_path, width, height) elif file_path.endswith('.svg'):