From 7a898089a568db4d720591d2e9abf9a675058fa5 Mon Sep 17 00:00:00 2001 From: Yotam Gingold Date: Thu, 26 Sep 2019 12:02:00 -0400 Subject: [PATCH 1/2] Update surface.py If only one of output_width or output_height is specified, then the other is inferred by preserving the aspect ratio. --- cairosvg/surface.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cairosvg/surface.py b/cairosvg/surface.py index 7f0fac8c..a5fb5568 100644 --- a/cairosvg/surface.py +++ b/cairosvg/surface.py @@ -198,6 +198,14 @@ def __init__(self, tree, output, dpi, parent_surface=None, if output_width and output_height: width, height = output_width, output_height + elif output_width: + ## Keep the aspect ratio + height = float(height)/float(width)*output_width + width = output_width + elif output_height: + ## Keep the aspect ratio + width = float(width)/float(height)*output_height + height = output_height else: width *= scale height *= scale From 279fff1d22c804792b15b9d03fb4019cd75711a7 Mon Sep 17 00:00:00 2001 From: Yotam Gingold Date: Fri, 11 Oct 2019 11:38:52 -0400 Subject: [PATCH 2/2] Update surface.py Fixed comment with two ## --- cairosvg/surface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cairosvg/surface.py b/cairosvg/surface.py index a5fb5568..2cb323d9 100644 --- a/cairosvg/surface.py +++ b/cairosvg/surface.py @@ -199,11 +199,11 @@ def __init__(self, tree, output, dpi, parent_surface=None, if output_width and output_height: width, height = output_width, output_height elif output_width: - ## Keep the aspect ratio + # Keep the aspect ratio height = float(height)/float(width)*output_width width = output_width elif output_height: - ## Keep the aspect ratio + # Keep the aspect ratio width = float(width)/float(height)*output_height height = output_height else: