Skip to content

Commit

Permalink
Merge pull request #88 from meerk40t/fill-opacity-bug
Browse files Browse the repository at this point in the history
Setting Fill-Opacity on Fill=None
  • Loading branch information
tatarize authored Dec 22, 2020
2 parents ec9e487 + 5cb2552 commit 6f31d70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = svgelements
version = 1.4.0
version = 1.4.1
description = Svg Elements Parsing
long_description_content_type=text/markdown
long_description = file: README.md
Expand Down
6 changes: 3 additions & 3 deletions svgelements/svgelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
and the Arc can do exact arc calculations if scipy is installed.
"""

SVGELEMENTS_VERSION = "1.4.0"
SVGELEMENTS_VERSION = "1.4.1"

MIN_DEPTH = 5
ERROR = 1e-12
Expand Down Expand Up @@ -3054,15 +3054,15 @@ def property_by_values(self, values):
stroke = values.get(SVG_ATTR_STROKE)
self.stroke = Color(stroke) if stroke is not None else None
stroke_opacity = values.get(SVG_ATTR_STROKE_OPACITY)
if stroke_opacity is not None and self.stroke is not None:
if stroke_opacity is not None and self.stroke is not None and self.stroke.value is not None:
try:
self.stroke.opacity = float(stroke_opacity)
except ValueError:
pass
fill = values.get(SVG_ATTR_FILL)
self.fill = Color(fill) if fill is not None else None
fill_opacity = values.get(SVG_ATTR_FILL_OPACITY)
if fill_opacity is not None and self.fill is not None:
if fill_opacity is not None and self.fill is not None and self.fill.value is not None:
try:
self.fill.opacity = float(fill_opacity)
except ValueError:
Expand Down
8 changes: 8 additions & 0 deletions test/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ def test_solo_move(self):
self.assertEqual(move_2_places.point(1), 1 + 1j)
self.assertEqual(move_2_places.length(), 0)

def test_fill_opacity_fill_none(self):
s = io.StringIO('<svg><path d="M0,0 H10 V10 H0 z" fill-opacity="1" fill="none" /></svg>')
svg = SVG.parse(s)
for e in svg.elements():
if isinstance(e, Path):
self.assertEqual(e, "M0,0 H10 V10 H0 z")
self.assertEqual(e.fill, "none" )


class TestParseDisplay(unittest.TestCase):
"""
Expand Down

0 comments on commit 6f31d70

Please sign in to comment.