Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Don't draw an outline for SVG shapes with stroke="none" (#5036)

Rızgar Ozan34681ed712fc
diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py
index 75cfd621d..722efb292 100644
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@ -375,8 +375,9 @@ class SVGMobject(VMobject, metaclass=ConvertToOpenGL):
shape
The parsed SVG element.
"""
+ # stroke="none" still inherits a stroke-width, but has no color to draw it with
mob.set_style(
- stroke_width=shape.stroke_width,
+ stroke_width=shape.stroke_width if shape.stroke.value is not None else 0,
stroke_color=shape.stroke.hexrgb,
stroke_opacity=shape.stroke.opacity,
fill_color=shape.fill.hexrgb,
diff --git a/tests/module/mobject/svg/test_svg_mobject.py b/tests/module/mobject/svg/test_svg_mobject.py
index 742525cbd..c858a33f8 100644
--- a/tests/module/mobject/svg/test_svg_mobject.py
+++ b/tests/module/mobject/svg/test_svg_mobject.py
@@ -73,6 +73,35 @@ def test_empty_path_is_ignored(tmp_path: Path):
assert svg.submobjects[0].has_points()
+def test_none_stroke_and_fill_are_not_drawn(tmp_path: Path):
+ svg_path = tmp_path / "none_paint.svg"
+ svg_path.write_text(
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
+ '<g stroke="#000" stroke-width="4" fill="#f00">'
+ '<rect x="10" y="10" width="80" height="80"/>'
+ '<rect x="30" y="30" width="40" height="40" stroke="none"/>'
+ '<path d="M 40 40 L 60 40 L 60 60 Z" stroke="none" stroke-width="3"/>'
+ '<rect x="45" y="45" width="10" height="10" fill="none"/>'
+ '<path d="M 45 45 L 55 45 L 55 55 Z" fill="none"/>'
+ "</g>"
+ "</svg>",
+ encoding="utf-8",
+ )
+
+ outer, stroke_none_rect, stroke_none_path, fill_none_rect, fill_none_path = (
+ SVGMobject(svg_path).submobjects
+ )
+
+ assert outer.get_stroke_width() == 4
+ assert outer.get_fill_opacity() == 1
+ assert stroke_none_rect.get_stroke_width() == 0
+ assert stroke_none_path.get_stroke_width() == 0
+ assert stroke_none_rect.get_fill_opacity() == 1
+ assert fill_none_rect.get_fill_opacity() == 0
+ assert fill_none_path.get_fill_opacity() == 0
+ assert fill_none_rect.get_stroke_width() == 4
+
+
def test_single_path_turns_into_sequence_of_points():
svg = SVGMobject(
get_svg_resource("cubic_and_lineto.svg"),
diff --git a/tests/test_graphical_units/control_data/img_and_svg/ManimLogo.npz b/tests/test_graphical_units/control_data/img_and_svg/ManimLogo.npz
index 709993dd8..b70f4a361 100644
Binary files a/tests/test_graphical_units/control_data/img_and_svg/ManimLogo.npz and b/tests/test_graphical_units/control_data/img_and_svg/ManimLogo.npz differ
diff --git a/tests/test_graphical_units/control_data/img_and_svg/WeightSVG.npz b/tests/test_graphical_units/control_data/img_and_svg/WeightSVG.npz
index 611edb3b6..5e7ecd7fb 100644
Binary files a/tests/test_graphical_units/control_data/img_and_svg/WeightSVG.npz and b/tests/test_graphical_units/control_data/img_and_svg/WeightSVG.npz differ