question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve the SVG parser

See original GitHub issue

There are many weird quirks of the current custom SVG parser. For example, the colors white and black are swapped if the SVG element is a rect. This is some really odd behavior, and I think the best way to solve these issues is to use a full SVG parsing library. Either way, SVG support is pretty limited at the moment. (Also, I think I can add SkewX and SkewY transform support right now)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

4reactions
xy-23commented, May 22, 2020

Hi, I was trying to improve the svg parser sometime ago, but during my attempt, I found if we want to improve it (more stable and powerful), we need to deal with some problems first.

  1. We need to let SVGMobject support <text>, <image> and so on. But currently SVGMobject is a subclass of VMobject. I think we should let SVGMobject become a subclass of Group, which I think is more intuitive. But then you will find that Group doesn’t support many existingAnimations e.g. Write, and you will also notice that there is a subclass of VMobject called VGroup, so far, I have made a new class called Image which is a subclass of VMobject/.../Rectangle and is able to be animated in those Animations, but I think it is a compromised way. Then we need to dig into the deepest process of manim, if you are interested, please tell me, because I think this is a little offtopic…

  2. We need to PARSE svg in a better way in order to let it support attributes like color, stroke and so on. I found a python package called cairosvg, which does this job almost perfectly, but it can’t be used directly in manim, so I think we can probably look into the source code of it and use(copy) some of it such as its class called Tree

Because I’m busy with other things now and don’t have much time to do it. If you want to improve it, I hope my experience can help a little…

1reaction
xy-23commented, May 23, 2020

Keep in mind that Image is also a part of PIL, so to minimise confusion, a better name should be chosen imo.

I just use the name Image to distinguish the current ImageMobject, but I think using the name Image, Text, Tex, SVG, is simpler and more convince to use from user‘s perspective than ImageMobject, TextMobject, TexMobject, SVGMobject (though they are not the same thing currently).

The confusion of the PIL Image can probably be solved by using PIL.Image.

Maybe we can do something like this:

class ImageMobject():
    def __init__(self):
        pass

and create a abbreviation version

class Image(ImageMobject):
    pass

But this is not very important…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improving SVG Runtime Performance - CodePen
Receiving and decoding data from the network takes CPU. The less of that, the more cycles left over for rendering. Plus, parse time...
Read more >
C/C++ library to parse SVG files?
New SVG++ library is a good choice for SVG reading in C++, except that it is not lightweight and requires Boost library.
Read more >
Python SVG parser - Stack Overflow
Ignoring transforms, you can extract the path strings from an SVG like so: from xml.dom import minidom doc = minidom.parse(svg_file) # parseString also ......
Read more >
SVG++ 1.2.1 released: Most advanced SVG reading library for ...
Can I use to build a SVG ? What are you using Boost for ? XML parsing and blas ?
Read more >
Re: Go SVG Parser? - Google Groups
I needed to manipulate SVG files, so I wrote a program (in Go) to put the SVG in to a generic tree (using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found