Utility functions for parsing SVG styles.
Functions
cascade_element_style
(element, inherited)[source]¶Collect the element’s style attributes based upon both its inheritance and its own attributes.
SVG uses cascading element styles. A closer ancestor’s style takes precedence over a more distant ancestor’s style. In order to correctly calculate the styles, the attributes are passed down through the inheritance tree, updating where necessary.
Note that this method only copies the values and does not parse them. See parse_color_string()
for converting
from SVG attributes to manim keyword arguments.
element (MinidomElement
) – Element of the SVG parse tree
inherited (dict
) – Dictionary of SVG attributes inherited from the parent element.
Dictionary mapping svg attributes to values with element’s values overriding inherited values.
dict
fill_default_values
(svg_style)[source]¶Fill in the default values for properties of SVG elements, if they are not currently set in the style dictionary.
svg_style (dict
) – Style dictionary with SVG property names. Some may be missing.
Style attributes; none are missing.
dict
parse_color_string
(color_spec)[source]¶Handle the SVG-specific color strings and convert them to HTML #rrggbb format.
color_spec (str
) – String in any web-compatible format
Hexadecimal color string in the format #rrggbb
str
parse_style
(svg_style)[source]¶Convert a dictionary of SVG attributes to Manim VMobject keyword arguments.
svg_style (dict
) – Style attributes as a string-to-string dictionary. Keys are valid SVG element attributes (fill, stroke, etc)
Style attributes, but in manim kwargs form, e.g., keys are fill_color, stroke_color
dict