Skip to content

Add support for Inkscape SVGs #168

@cobordism

Description

@cobordism

Situation:
I have a maths paper. I run pdf2svg or dvisvgm. I modify the svg with inkscape just minimally (for example I change the grouping of elements). I try to load it with SVGMobject. This fails.

Cause of the Problem:
Manim does not expect g and defs tags to have an id.
They have no id on dvisvgm output, but they do when saving the same svg from Inkscape.

Solution in svg_mobject.py replace get_all_childNodes_have_id with

    def get_all_childNodes_have_id(self, element):
        all_childNodes_have_id = []
        if not isinstance(element, minidom.Element):
            return
        if element.hasAttribute('id') and (
                not element.tagName == "g"
                and
                not element.tagName == "defs"
                ):
            return [element]
        for e in element.childNodes:
            all_childNodes_have_id.append(self.get_all_childNodes_have_id(e))
        return self.flatten([e for e in all_childNodes_have_id if e])

Metadata

Metadata

Assignees

Labels

enhancementAdditions and improvements in generalpr:bugfixBug fix for use in PRs solving a specific issue:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions