From 9d280dbeda774af24d4ee4ef81452bccb0810044 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 9 Apr 2022 19:13:07 +0200 Subject: [PATCH] Fixed default value of Rect.rx/ry if only one is specified --- CHANGELOG.rst | 1 + svglib/svglib.py | 4 ++++ tests/test_basic.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f581b65..ae392d6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ Unreleased - Support mmult import from reportlab < 3.5.61 (#316). - ```` nodes now only appears in documents when they are referenced, not on their initial appearance. +- If only rx or ry is defined on a ````, the value is used for both. 1.2.1 (2022-01-27) ------------------ diff --git a/svglib/svglib.py b/svglib/svglib.py index e9ded9b..b7d3dc4 100755 --- a/svglib/svglib.py +++ b/svglib/svglib.py @@ -983,6 +983,10 @@ def convertRect(self, node): rx = width / 2 if ry > (height / 2): ry = height / 2 + if rx and not ry: + ry = rx + elif ry and not rx: + rx = ry return Rect(x, y, width, height, rx=rx, ry=ry) def convertCircle(self, node): diff --git a/tests/test_basic.py b/tests/test_basic.py index 1a665c9..d3852ad 100755 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -710,6 +710,20 @@ def test_rx_ry(self): assert rect.rx == 5 assert rect.ry == 1.5 + def test_rx_ry_lonely(self): + """If only rx or ry is present, the other default to the same value.""" + converter = svglib.Svg2RlgShapeConverter(None) + node = svglib.NodeTracker(etree.XML( + '' + )) + rect = converter.convertRect(node) + assert rect.ry == 2.5 + node = svglib.NodeTracker(etree.XML( + '' + )) + rect = converter.convertRect(node) + assert rect.rx == 1 + def test_strokewidth_0(self): """ When strokeWidth = 0, we force strokeColor to None to avoid the stroke