style_utils#
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.- Parameters
element (
MinidomElement
) – Element of the SVG parse treeinherited (
dict
) – Dictionary of SVG attributes inherited from the parent element.
- Returns
Dictionary mapping svg attributes to values with element’s values overriding inherited values.
- Return type
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.
- Parameters
svg_style (
dict
) – Style dictionary with SVG property names. Some may be missing.- Returns
Style attributes; none are missing.
- Return type
dict
- parse_color_string(color_spec)[source]#
Handle the SVG-specific color strings and convert them to HTML #rrggbb format.
- Parameters
color_spec (
str
) – String in any web-compatible format- Returns
Hexadecimal color string in the format #rrggbb
- Return type
str
- parse_style(svg_style)[source]#
Convert a dictionary of SVG attributes to Manim VMobject keyword arguments.
- Parameters
svg_style (
dict
) – Style attributes as a string-to-string dictionary. Keys are valid SVG element attributes (fill, stroke, etc)- Returns
Style attributes, but in manim kwargs form, e.g., keys are fill_color, stroke_color
- Return type
dict