Skip to content

Commit

Permalink
Fixed default value of Rect.rx/ry if only one is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed May 11, 2022
1 parent d1abe3c commit 9d280db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
- Support mmult import from reportlab < 3.5.61 (#316).
- ``<symbol>`` nodes now only appears in documents when they are
referenced, not on their initial appearance.
- If only rx or ry is defined on a ``<rect>``, the value is used for both.

1.2.1 (2022-01-27)
------------------
Expand Down
4 changes: 4 additions & 0 deletions svglib/svglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 rx="2.5" width="10" height="3" x="0" y="0"/>'
))
rect = converter.convertRect(node)
assert rect.ry == 2.5
node = svglib.NodeTracker(etree.XML(
'<rect ry="1" width="10" height="3" x="0" y="0"/>'
))
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
Expand Down

0 comments on commit 9d280db

Please sign in to comment.