Skip to content

SVG

keyed_extras.svg

SVG-related renderable objects.

Experimental

This module is highly experimental.

SVGShapes

Bases: Selection

Create a collection of native keyed objects from an SVG file's contents.

This class makes a best effort attempt to parse supported objects from SVG files and convert them into native keyed objects. Supported object types include:

- Rect
- Circle
- Ellipse
- Polygon
- PolyLine
- Line
- Path
Warning

We'll attempt to parse things like size/position, fill color, stroke color, line width, and other simple styling information.

We will not support the full SVG spec.

For more complete support of complex SVGs, consider using the SVG object.

Experimental

This class is highly experimental.

Parameters:

Name Type Description Default
scene Scene

Scene to which the SVG belongs

required
file_name str | Path

Path to the SVG file

required
center bool

Whether to center the SVG after importing

True
height float | None

Target height in scene units (None uses original size)

None
width float | None

Target width in scene units (None uses original size)

None
color tuple[float, float, float] | HasValue[Color] | None

Color override (None uses SVG colors)

None
fill_color tuple[float, float, float] | HasValue[Color] | None

Fill color override (None uses SVG colors)

None
stroke_color tuple[float, float, float] | HasValue[Color] | None

Stroke color override (None uses SVG colors)

None
alpha float

Overall opacity

1.0
stroke_width float | None

Stroke width override (None uses SVG values)

None

keyed_extras.svg.rsvg

SVG rendering support.

SVG

Bases: Base

A drawable SVG object.

This object renders the underlying SVG object literally.

Experimental

This class is highly experimental.

Warning

This requires librsvg and pygobjects installed as system level dependencies.

Parameters:

Name Type Description Default
scene Scene

Scene to draw the SVG on

required
svg_path str | Path

Path to SVG file

required
width float | None

Width to draw SVG (defaults to original width)

None
height float | None

Height to draw SVG (defaults to original height)

None
x float | None

x position of SVG on canvas (defaults to center of canvas)

None
y float | None

y position of SVG on canvas (defaults to center of canvas)

None