-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse and generate style for SVG #1717
Conversation
This looks great, thanks for doing it |
Yes, it's because the styles are defined by the css in the <style> tag, which is not handled yet (nor is ManimCommunity). I'll try my best to handle this situation when I have time :) |
I agree it seems a little tricky. I mostly just wanted to keep track of an edge case here, don't feel like it's something you have to do. Also, just FYI, I made a few quick fixes based on its behavior with Text and MTex |
Motivation
Before,
SVGMobject
will remove all styles from a svg file.This pull request parse the style for SVG by refering to ManimCommunity/manim.
In order to prevent the style generated layer by layer in
init_points
from being globally overwritten by theinit_colors
after it. I added a parameteroverride
toinit_colors
, which is set toTrue
by default (that is, consistent with the original performance), but whenoverride = False
, it will recurse layer by layer and set the color to the currently generated color.Proposed changes
manimlib/mobject/svg/svg_mobject.py
: add SVG style parser and fix some bugs of path stringmanimlib/mobject/types/vectorized_mobject.py
: addoverride
parameter toinit_colors
manimlib/mobject/mobject.py
: synchronously update the parameters ofinit_colors
manimlib/mobject/geometry.py
: synchronously update the parameters ofinit_colors
manimlib/mobject/types/surface.py
: synchronously update the parameters ofinit_colors
manimlib/mobject/svg/tex_mobject.py
: synchronously update the parameters ofinit_colors
and synchronizeSingleStringTex
'sstroke_width
toSVGMobject
manimlib/mobject/svg/tex_mobject.py
: cache color intex_string_to_mob_map
together with tex_stringmanimlib/mobject/svg/text_mobject.py
: replacewarnings.warn
withlog.warning
Test
I tested all the svg files used in ManimCE for testing and each file renders correctly with color and stroke.
And
Tex
TexText
can correctly generate texts with color according to the corresponding LaTeX expression (\color{}
)Code:
Result:
As can be seen from the above example, the color parameter is only the default color, and this color will be overwritten as long as a color is included in the SVG. If you want to ignore the color in SVG, you can directly
.set_color
again.