Parse and generate style for SVG #1717
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.