Skip to content

Commit

Permalink
Merge pull request #153 from meerk40t/1.6.5
Browse files Browse the repository at this point in the history
1.6.5
  • Loading branch information
tatarize authored Dec 1, 2021
2 parents 32d6c94 + 0368a7b commit 57b8bda
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 8 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.6.4
version = 1.6.5
description = Svg Elements Parsing
long_description_content_type=text/markdown
long_description = file: README.md
Expand Down
28 changes: 24 additions & 4 deletions svgelements/svgelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
and the Arc can do exact arc calculations if scipy is installed.
"""

SVGELEMENTS_VERSION = "1.6.4"
SVGELEMENTS_VERSION = "1.6.5"

MIN_DEPTH = 5
ERROR = 1e-12
Expand Down Expand Up @@ -3727,7 +3727,11 @@ def bbox(self, transformed=True, with_stroke=False):
except ValueError:
return None # No bounding box items existed. So no bounding box.

if with_stroke and self.stroke_width is not None:
if (
with_stroke
and self.stroke_width is not None
and not (self.stroke is None or self.stroke.value is None)
):
if transformed:
delta = float(self.implicit_stroke_width) / 2.0
else:
Expand Down Expand Up @@ -7349,7 +7353,11 @@ def bbox(self, transformed=True, with_stroke=False):
except ValueError:
return None # No bounding box items existed. So no bounding box.

if with_stroke and self._path.stroke_width is not None:
if (
with_stroke
and self._path.stroke_width is not None
and not (self._path.stroke is None or self._path.stroke.value is None)
):
delta = float(self._path.stroke_width) / 2.0
else:
delta = 0.0
Expand Down Expand Up @@ -7912,7 +7920,11 @@ def bbox(self, transformed=True, with_stroke=False):
xmax = max(p0[0], p1[0], p2[0], p3[0])
ymax = max(p0[1], p1[1], p2[1], p3[1])

if with_stroke and self.stroke_width is not None:
if (
with_stroke
and self.stroke_width is not None
and not (self.stroke is None or self.stroke.value is None)
):
if transformed:
delta = float(self.implicit_stroke_width) / 2.0
else:
Expand Down Expand Up @@ -8727,6 +8739,13 @@ def parse(
root.objects[attributes[SVG_ATTR_ID]] = s
elif event == "end": # End event.
# The iterparse spec makes it clear that internal text data is undefined except at the end.
if (
SVG_ATTR_DISPLAY in values
and values[SVG_ATTR_DISPLAY].lower() == SVG_VALUE_NONE
):
# We are in a display=none, do not render this. Pop values and continue.
context, values = stack.pop()
continue
s = None
if tag in (
SVG_TAG_TEXT,
Expand Down Expand Up @@ -8787,5 +8806,6 @@ def parse(
context, values = stack.pop()
elif event == "start-ns":
if elem[0] != SVG_ATTR_DATA:
# Rare wc3 test uses a 'd' namespace.
values[elem[0]] = elem[1]
return root
103 changes: 100 additions & 3 deletions test/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def test_bbox_rect_stroke(self):
'y': "51",
'width': "20",
'height': "10",
'stroke-width': "5"
'stroke-width': "5",
'stroke': 'red',
}
e = Rect(values)
self.assertEqual(e.bbox(), (50, 51, 70, 61))
Expand Down Expand Up @@ -88,7 +89,8 @@ def test_bbox_path_stroke(self):
'y': "51",
'width': "20",
'height': "10",
'stroke-width': "5"
'stroke-width': "5",
'stroke': 'red',
}
e = Path(Rect(values))
self.assertEqual(e.bbox(), (50, 51, 70, 61))
Expand Down Expand Up @@ -122,6 +124,100 @@ def test_bbox_path_stroke(self):
61 + (5. / 2.)
))

def test_bbox_path_stroke_none(self):
"""
Same as test_bbox_path_stroke but stroke is set to none, so the bbox should not change.
"""
values = {
'tag': 'rect',
'rx': "4",
'ry': "2",
'x': "50",
'y': "51",
'width': "20",
'height': "10",
'stroke-width': "5",
'stroke': "none",
}
e = Path(Rect(values))
self.assertEqual(e.bbox(), (50, 51, 70, 61))
self.assertEqual(e.bbox(with_stroke=True), (
50,
51,
70,
61
))
e *= "translate(2)"
self.assertEqual(e.bbox(), (52, 51, 72, 61))
self.assertEqual(e.bbox(with_stroke=True), (
52,
51,
72,
61
))
e *= "scale(2)"
self.assertEqual(e.bbox(), (52 * 2, 51 * 2, 72 * 2, 61 * 2))
self.assertEqual(e.bbox(with_stroke=True), (
52 * 2,
51 * 2,
72 * 2,
61 * 2
))
self.assertEqual(e.bbox(transformed=False), (50, 51, 70, 61))
self.assertEqual(e.bbox(transformed=False, with_stroke=True), (
50,
51,
70,
61
))

def test_bbox_path_stroke_unset(self):
"""
Same as test_bbox_path_stroke but the stroke is unset and thus shouldn't contribute to the bbox even if
with_stroke is set.
"""
values = {
'tag': 'rect',
'rx': "4",
'ry': "2",
'x': "50",
'y': "51",
'width': "20",
'height': "10",
'stroke-width': "5",
}
e = Path(Rect(values))
self.assertEqual(e.bbox(), (50, 51, 70, 61))
self.assertEqual(e.bbox(with_stroke=True), (
50,
51,
70,
61
))
e *= "translate(2)"
self.assertEqual(e.bbox(), (52, 51, 72, 61))
self.assertEqual(e.bbox(with_stroke=True), (
52,
51,
72,
61
))
e *= "scale(2)"
self.assertEqual(e.bbox(), (52 * 2, 51 * 2, 72 * 2, 61 * 2))
self.assertEqual(e.bbox(with_stroke=True), (
52 * 2,
51 * 2,
72 * 2,
61 * 2
))
self.assertEqual(e.bbox(transformed=False), (50, 51, 70, 61))
self.assertEqual(e.bbox(transformed=False, with_stroke=True), (
50,
51,
70,
61
))

def test_bbox_subpath(self):
values = {
'tag': 'rect',
Expand All @@ -147,7 +243,8 @@ def test_bbox_subpath_stroke(self):
'y': "51",
'width': "20",
'height': "10",
'stroke-width': "5"
'stroke-width': "5",
'stroke': 'red',
}
p = Path(Rect(values))
e = p.subpath(0)
Expand Down
15 changes: 15 additions & 0 deletions test/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,18 @@ def test_issue_107(self):
n = m * 'scale(2)' # Test __mult__
self.assertEqual(n[0][0].transform, Matrix("matrix(2,0,0,2,200,200)"))
self.assertEqual(m[0][0].transform, Matrix("matrix(1,0,0,1,100,100)"))

def test_issue_152(self):
"""
Tests issue 152, closed text objects within a group with style:display=None
This should have the SVG element and nothing else.
https://github.com/meerk40t/svgelements/issues/152
"""
q = io.StringIO(u'''<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg>
<g style="display:none">
<text><textPath><tspan>Issue 152</tspan></textPath></text>
</g>
</svg>''')
elements = list(SVG.parse(q).elements())
self.assertEqual(len(elements), 1)

0 comments on commit 57b8bda

Please sign in to comment.