Elements¶
Element classes. Every class also has a lowercase alias (svgwriter.circle is svgwriter.Circle).
Each class lists its own members and links to its bases: moving, rotating, aligning and the
center/top/… attributes are on Transformable, which every shape, group, image and text inherits.
Base classes¶
- class Element(*children: Element | str, id: str | None = None, attrs: Mapping[str, Any] | None = None, **extra: Any)[source]¶
Bases:
Construction,AttributeAccess,TreeEditing,Queryable,Displayable,ComposableBase class for every SVG element.
Attributes are kept in
attributesunder their SVG names; keyword arguments use Python spelling (stroke_width,class_,xlink_href) and are translated bysvg_name().- Parameters:
- Raises:
UnknownKeywordError – If a keyword is not a known SVG attribute.
See also
svgwriter.model.elements.ContainerElements that hold children.
Examples
>>> import svgwriter as svg >>> el = svg.rect(0, 0, 10, 10, stroke_width=2) >>> el.tag, el.attributes["stroke-width"] ('rect', 2)
- arranges_children: ClassVar[bool] = False¶
True for layout groups, which place their children before any child is measured.
- property id: str | None¶
The element id, or None.
Assigning validates the name as an XML name; assigning None removes it.
- Raises:
ValueError – On assignment, if the value is not a valid id.
Examples
>>> import svgwriter as svg >>> el = svg.rect(0, 0, 1, 1, id="a") >>> el.id 'a'
- property animate: Any¶
el.animate.fade_in(1).spin(2, begin=1).- Returns:
Motion – Chainable presets that add SMIL animation children.
Examples
>>> import svgwriter as svg >>> _ = svg.rect(0, 0, 10, 10).animate.fade_in()
- Type:
Animation presets for this element
- property interact: Any¶
button.interact.button(); add your own with@svg.preset.interaction.- Returns:
Interactions – The presets; each call applies one and returns this element.
Examples
>>> import svgwriter as svg >>> _ = svg.rect(0, 0, 10, 10).interact.highlight(color="crimson")
- Type:
Interaction presets for this element
- wireframe(*, color: str = '#0ea5e9', width: float | None = None, bounds: bool = False) Any[source]¶
A copy drawn as thin outlines, to see the geometry under the paint (for debugging).
- Parameters:
- Returns:
Element – The wireframe; this one is unchanged.
See also
svgwriter.ops.wireframeThe function behind it.
Examples
>>> import svgwriter as svg >>> svg.circle(5, 5, 4, fill="red").wireframe().style["fill"] 'none'
- property home: Element¶
a detached copy to start each frame from.
A behavior that sets the state from
home(element.matrix = element.home.matrix, then a relative move) computes every frame afresh, so the motion never drifts and frames can be drawn in any order.- Returns:
Element – The copy
Scene.attachtook.- Raises:
ValueError – If no behavior has been attached to this element.
See also
svgwriter.library.preset.behaviorWrite a behavior.
Examples
>>> import svgwriter as svg >>> class Hop(svg.Scene): ... width, height, duration = 40, 40, 1.0 ... def build(self, doc): ... self.dot = doc.circle(20, 30, 4).animate.hover(height=10).element >>> scene = Hop() >>> scene.dot.cy = 31 >>> float(scene.dot.home.cy) 30.0
- Type:
The element as it was when its first behavior was attached
- computed(name: str, default: object = None) object[source]¶
The value SVG would use for property name (SVG spelling or Python spelling).
Looks at the inline
style, matching<style>rules, the presentation attribute, then ancestors for inherited properties.- Parameters:
- Returns:
object – The property’s value, written as SVG text when it is not a plain number, or default.
Examples
>>> import svgwriter as svg >>> g = svg.group(fill="red", font_size=30) >>> t = g.add(svg.text("hi", style="font-size: 12px")) >>> t.computed("fill"), t.computed("font_size"), t.computed("opacity", 1) ('red', '12px', 1)
- clone(linked: Literal[False] = False) E[source]¶
- clone(linked: Literal[True]) Use
A deep, detached copy; or with linked, a
<use>that renders this element.- Parameters:
linked (bool) –
Falsecopies the whole subtree (pixels included), so edits never reach the original.Truereturns a<use>referencing this element (giving it an id), so edits to the original show through every linked clone.- Returns:
Element – A copy of the same class, or a
Use.
Notes
A linked clone needs the original in the same document: placed anywhere, or unplaced, in which case it moves into
<defs>when the<use>joins the document.copy.copyandcopy.deepcopyboth behave likeclone().Examples
>>> import svgwriter as svg >>> star = svg.circle(0, 0, 5, id="dot") >>> star.clone().id, star.clone(linked=True).tag ('dot', 'use')
- append(child: C) C¶
Append a child element or text node and return it.
An element that already has a parent is moved. Elements referenced by the child but not yet placed are collected into the root
<defs>.- Parameters:
- Returns:
Element or str – The appended child.
- Raises:
TypeError – If the content model forbids the child, or it is not an element or str.
See also
insertAdd a child at a given position.
Examples
>>> import svgwriter as svg >>> g = svg.group() >>> g.append(svg.circle(0, 0, 1)).tag 'circle'
- clear() None¶
Remove and detach every child.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1)) >>> g.clear() >>> len(g) 0
- discard(name: str) None¶
Remove an attribute if it is set.
- Parameters:
name (str) – The attribute name, Python or SVG spelling.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> r.discard("width") >>> r.has("width") False
- ensure_id() ElementId¶
Return the id, assigning a generated one if needed.
- Returns:
str – The existing or newly generated id.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1, id="a").ensure_id() 'a'
- extend(children: Iterable[Child]) None¶
Append every child in children.
Examples
>>> import svgwriter as svg >>> g = svg.group() >>> g.extend([svg.circle(0, 0, 1), svg.circle(1, 1, 1)]) >>> len(g) 2
- find(match: type[Element] | str) Element | None¶
First descendant (or self) matching a tag or class.
- Parameters:
- Returns:
Element or None – The first match in document order, or None.
See also
find_allEvery match.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1)) >>> g.find("circle").tag, g.find("rect") ('circle', None)
- find_all(match: type[Element] | str) list[Element]¶
Every descendant (and self) matching a tag or class.
- Parameters:
- Returns:
list of Element – The matches in document order.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1), svg.circle(1, 1, 1)) >>> len(g.find_all("circle")) 2
- classmethod from_attributes(attributes: Mapping[str, str]) E¶
Build an instance from raw SVG attributes, bypassing
__init__.- Parameters:
attributes (mapping of str to str) – Attributes by SVG name, stored as given.
- Returns:
Element – A new instance of this class.
Examples
>>> import svgwriter as svg >>> svg.Rect.from_attributes({"width": "5"}).attributes {'width': '5'}
- get(name: str, default: object = None) object¶
Return an attribute value, or default if it is not set.
A presentation property declared in the inline
styleis read from there, as it overrides the attribute.- Parameters:
- Returns:
object – The stored value or the default.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1, stroke_width=2) >>> r.get("stroke_width"), r.get("fill", "none") (2, 'none') >>> svg.rect(0, 0, 1, 1, style="fill:blue").get("fill") 'blue'
- get_element_by_id(element_id: str) Element | None¶
Find the element with the given id in this subtree.
- Parameters:
element_id (str) – The id to look for.
- Returns:
Element or None – The matching element, or None.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1, id="dot")) >>> g.get_element_by_id("dot").tag 'circle'
- has(name: str) bool¶
Report whether an attribute is set.
- Parameters:
name (str) – The attribute name, Python or SVG spelling.
- Returns:
bool – True if the attribute is present.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1).has("width") True
- insert(index: int, child: C) C¶
Insert a child at index and return it.
- Parameters:
- Returns:
Element or str – The inserted child.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1)) >>> _ = g.insert(0, svg.rect(0, 0, 1, 1)) >>> [c.tag for c in g] ['rect', 'circle']
- property iri: IRI¶
#idpointing at this element, assigning an id if needed.Use it where SVG expects a plain IRI (
xlink:hrefof<use>,<mpath>, …); passing the element itself does the same. An element’s ownxlink:hrefisel.href.See also
urlThe
url(#id)form.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1, id="a").iri.svg_value() '#a'
- iter(tag: str | None = None, *, max_depth: float = inf) Iterator[Element]¶
Depth-first walk over this element and its descendants.
- Parameters:
- Yields:
Element – Elements in document order, starting with this one.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1), svg.rect(0, 0, 1, 1)) >>> [e.tag for e in g.iter()] ['g', 'circle', 'rect']
- property label: str | None¶
A readable name for the element, stored as
inkscape:label, or None.Inkscape shows it in its Layers and Objects panels, and
doc["name"]finds an element by label when no id matches. Assigning None removes it.Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> r.label = "Logo" >>> r.label, r.attributes["inkscape:label"] ('Logo', 'Logo')
- classmethod lookup(tag: str) type[Element] | None¶
Return the registered class for tag.
- Parameters:
tag (str) – An SVG tag name.
- Returns:
type[Element] or None – The class registered for the tag, or None if there is none.
Examples
>>> import svgwriter as svg >>> svg.Element.lookup("rect").__name__ 'Rect'
- classmethod many(**columns: Any) list[E]¶
Build many elements at once from columns that broadcast like numpy.
Each keyword is an attribute in Python spelling; a scalar applies to every element and an array gives one value per element. Colors may be one color, a list of colors or an
(n, 3|4)array of 0-1 floats.- Parameters:
**columns – Attribute name to scalar or sequence.
- Returns:
list of Element – The new elements, ready for
doc.group(*elements)ordoc.add_all.- Raises:
ValueError – If the columns do not broadcast to one length.
Examples
>>> import numpy as np >>> import svgwriter as svg >>> dots = svg.Circle.many(cx=np.arange(3) * 10, cy=5, r=2, fill=["red", "green", "blue"]) >>> [str(d) for d in dots][1] '<circle cx="10" cy="5" r="2" fill="green"/>'
- classmethod registered(category: Category | None = None) dict[str, type[Element]]¶
Registered element classes, optionally filtered by category.
- Parameters:
category (Category, optional) – Keep only classes of this category. Defaults to None (all).
- Returns:
dict[str, type[Element]] – Registered classes keyed by tag.
Examples
>>> import svgwriter as svg >>> "circle" in svg.Element.registered() True
- remove(child: Child) None¶
Remove a child and detach it from this element.
- Parameters:
- Raises:
ValueError – If the child is not present.
Examples
>>> import svgwriter as svg >>> c = svg.circle(0, 0, 1) >>> g = svg.group(c) >>> g.remove(c) >>> len(g) 0
- root() Element¶
Return the topmost ancestor, or this element if it has no parent.
- Returns:
Element – The root of the tree this element belongs to.
Examples
>>> import svgwriter as svg >>> c = svg.circle(0, 0, 1) >>> g = svg.group(c) >>> c.root() is g True
- save(target: AnyPath | TextSink, **options: Any) None¶
Write to a path or text stream.
- Parameters:
target (path or text stream) – Where to write the SVG markup.
**options – Serialization options, as for
to_string().
See also
to_stringSerialize to a string.
Examples
>>> import io >>> import svgwriter as svg >>> buffer = io.StringIO() >>> svg.circle(0, 0, 1).save(buffer, xml_declaration=False, pretty=False) >>> buffer.getvalue() '<circle cx="0" cy="0" r="1"/>'
- set(name: str, value: AttrValue) None¶
Set one attribute;
Noneremoves it.Attributes in other namespaces use Clark notation:
"{uri}name". Colors with alpha are split into the color and its*-opacityattribute, and elements are replaced by references to them. A presentation property the inlinestylealready declares (as Inkscape writes them) is changed there, where it takes effect.- Parameters:
- Raises:
TypeError – If a length, angle or ~svgwriter.Quantity has the wrong dimension for the attribute (
widthgiven an area).ValueError – If the attribute is unsupported, a color string is not a valid color or paint, or a color with alpha is given to an attribute without an opacity counterpart.
See also
updateSet several attributes at once.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> _ = r.set("stroke_width", 3) >>> r.attributes["stroke-width"] 3 >>> styled = svg.rect(0, 0, 1, 1, style="fill:#ff0000") >>> styled.fill = "blue" >>> styled.attributes["style"], styled.has("fill") (Style({'fill': 'blue'}), False)
- property text_content: str¶
All character data below this element, in document order (the DOM
textContent).Assigning replaces every child with the single string.
Examples
>>> import svgwriter as svg >>> t = svg.text("Hello world") >>> t[6:].fill = "red" >>> t.text_content 'Hello world' >>> title = svg.Title("Old") >>> title.text_content = "New" >>> str(title) '<title>New</title>'
- to_string(**options: Any) str¶
Serialize to an SVG string; see
svgwriter.formats.io.SerializeOptions.- Parameters:
**options – Serialization options such as
prettyorxml_declaration.- Returns:
str – The SVG markup.
See also
saveWrite to a file or stream.
Examples
>>> import svgwriter as svg >>> svg.circle(0, 0, 1).to_string(xml_declaration=False, pretty=False) '<circle cx="0" cy="0" r="1"/>'
- update(attributes: Mapping[str, AttrValue] | None = None, /, **kwargs: AttrValue) None¶
Set several attributes;
Nonevalues are skipped.- Parameters:
attributes (mapping, optional) – Attributes by name. Defaults to None.
**kwargs – More attributes, Python spelling.
See also
setSet a single attribute.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> _ = r.update(fill="red", stroke=None) >>> r.get("fill") 'red'
- property url: FuncIRI¶
url(#id)pointing at this element, assigning an id if needed.Use it where SVG expects a functional IRI (
fill,clip-path,filter); passing the element itself does the same.See also
iriThe plain
#idform.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1, id="a").url.svg_value() 'url(#a)'
- class Transformable(*args: Element | str, transform: Transform | TransformOp | Matrix | str | None = None, anchor: tuple[float, float] | Point | str | None = None, **kwargs: Any)[source]¶
Bases:
Placement,TransformMethods,ElementAn element placed by a transform.
The element’s own geometry attributes (
cx,x,d, …) are local coordinates and stay as written; every move goes throught. Rotation, scaling and skewing pivot onanchor.- Parameters:
See also
svgwriter.model.elements._behavior.ConvertibleConversions and clipping on top of this class.
Notes
tis one affine matrix. Every method multiplies into it (before it in the parent frame, after it withlocal=True) instead of appending to a list; output is the shortest equivalenttransform.Examples
>>> import svgwriter as svg >>> c = svg.circle(50, 50, 10).translate(10, 0).rotate(90) >>> str(c.matrix) 'rotate(90 55 55)' >>> c.position Point(x=60.0, y=50.0)
- property anchor: Point¶
Pivot in local coordinates; the bounding-box centre unless set.
Assign a point, or a name read on the element’s own box each time, so it follows edits:
"center","top","bottom","left","right","top_left","top_right","bottom_left","bottom_right"(and the otherBBox.point()names),"origin"for local(0, 0), or, on text,"baseline"for the start of its first baseline. AssignNoneto go back to the centre. The same names work asabout=in every transform method and animation preset.- Raises:
ValueError – On assigning an unknown name; the message lists the valid ones.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 10, 4) >>> r.anchor Point(x=5.0, y=2.0) >>> r.anchor = "bottom" >>> r.anchor Point(x=5.0, y=4.0)
- property matrix: Matrix¶
The transform as an affine
Matrix; assign to replace it.Written to SVG as the shortest equivalent
transformtext.Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1).translate(2, 3).matrix.apply(0, 0) Point(x=2.0, y=3.0)
- align(target: Any, at: str = 'center', *, to: str | None = None, offset: PointLike = (0.0, 0.0)) E¶
Move the element so its point at meets the point to of target.
- Parameters:
target (Element, BBox or (float, float)) – What to align with; an element’s
bounds()are used.at (str, optional) – Named point of this element’s bounds. Defaults to
"center".to (str, optional) – Named point of the target. Defaults to at, so
a.align(b, "left")lines up left edges anda.align(b, "top", to="bottom")stacks a under b.offset ((float, float), optional) – Extra shift after aligning, for gaps. Defaults to
(0, 0).
- Returns:
Transformable – This element.
- Raises:
TypeError – If either size is unknown or target is not an element, box or point.
See also
placeMove to a coordinate.
BBox.pointThe point names.
Examples
>>> import svgwriter as svg >>> base = svg.rect(0, 0, 40, 10) >>> label = svg.rect(0, 0, 10, 4).align(base, "top", to="bottom", offset=(0, 2)) >>> label.bounds() BBox(x=15.0, y=12.0, width=10.0, height=4.0)
- append(child: C) C¶
Append a child element or text node and return it.
An element that already has a parent is moved. Elements referenced by the child but not yet placed are collected into the root
<defs>.- Parameters:
- Returns:
Element or str – The appended child.
- Raises:
TypeError – If the content model forbids the child, or it is not an element or str.
See also
insertAdd a child at a given position.
Examples
>>> import svgwriter as svg >>> g = svg.group() >>> g.append(svg.circle(0, 0, 1)).tag 'circle'
- apply(transform: TransformLike, *, local: bool = False) E¶
Compose an arbitrary transform (no pivot), in the parent frame unless local.
- Parameters:
- Returns:
Transformable – This element.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1).apply("translate(4 5)").position Point(x=4.5, y=5.5)
- bounds() BBox | None¶
Bounding box in parent coordinates (after
t).- Returns:
BBox or None – The box enclosing the transformed local box, or None when unknown.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 2, 2).translate(5, 5).bounds() BBox(x=5.0, y=5.0, width=2.0, height=2.0)
- clear() None¶
Remove and detach every child.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1)) >>> g.clear() >>> len(g) 0
- discard(name: str) None¶
Remove an attribute if it is set.
- Parameters:
name (str) – The attribute name, Python or SVG spelling.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> r.discard("width") >>> r.has("width") False
- ensure_id() ElementId¶
Return the id, assigning a generated one if needed.
- Returns:
str – The existing or newly generated id.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1, id="a").ensure_id() 'a'
- extend(children: Iterable[Child]) None¶
Append every child in children.
Examples
>>> import svgwriter as svg >>> g = svg.group() >>> g.extend([svg.circle(0, 0, 1), svg.circle(1, 1, 1)]) >>> len(g) 2
- find(match: type[Element] | str) Element | None¶
First descendant (or self) matching a tag or class.
- Parameters:
- Returns:
Element or None – The first match in document order, or None.
See also
find_allEvery match.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1)) >>> g.find("circle").tag, g.find("rect") ('circle', None)
- find_all(match: type[Element] | str) list[Element]¶
Every descendant (and self) matching a tag or class.
- Parameters:
- Returns:
list of Element – The matches in document order.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1), svg.circle(1, 1, 1)) >>> len(g.find_all("circle")) 2
- flip_x(*, about: Pivot | None = None, local: bool = False) E¶
Mirror left-right (across the vertical line through the anchor) and return
self.- Parameters:
- Returns:
Transformable – This element.
See also
flip_yMirror top-bottom.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 10, 10).flip_x(about=(0, 0)).bounds() BBox(x=-10.0, y=0.0, width=10.0, height=10.0)
- flip_y(*, about: Pivot | None = None, local: bool = False) E¶
Mirror top-bottom (across the horizontal line through the anchor) and return
self.- Parameters:
- Returns:
Transformable – This element.
See also
flip_xMirror left-right.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 10, 10).flip_y(about=(0, 0)).bounds() BBox(x=0.0, y=-10.0, width=10.0, height=10.0)
- classmethod from_attributes(attributes: Mapping[str, str]) E¶
Build an instance from raw SVG attributes, bypassing
__init__.- Parameters:
attributes (mapping of str to str) – Attributes by SVG name, stored as given.
- Returns:
Element – A new instance of this class.
Examples
>>> import svgwriter as svg >>> svg.Rect.from_attributes({"width": "5"}).attributes {'width': '5'}
- get(name: str, default: object = None) object¶
Return an attribute value, or default if it is not set.
A presentation property declared in the inline
styleis read from there, as it overrides the attribute.- Parameters:
- Returns:
object – The stored value or the default.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1, stroke_width=2) >>> r.get("stroke_width"), r.get("fill", "none") (2, 'none') >>> svg.rect(0, 0, 1, 1, style="fill:blue").get("fill") 'blue'
- get_element_by_id(element_id: str) Element | None¶
Find the element with the given id in this subtree.
- Parameters:
element_id (str) – The id to look for.
- Returns:
Element or None – The matching element, or None.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1, id="dot")) >>> g.get_element_by_id("dot").tag 'circle'
- has(name: str) bool¶
Report whether an attribute is set.
- Parameters:
name (str) – The attribute name, Python or SVG spelling.
- Returns:
bool – True if the attribute is present.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1).has("width") True
- property id: str | None¶
The element id, or None.
Assigning validates the name as an XML name; assigning None removes it.
- Raises:
ValueError – On assignment, if the value is not a valid id.
Examples
>>> import svgwriter as svg >>> el = svg.rect(0, 0, 1, 1, id="a") >>> el.id 'a'
- insert(index: int, child: C) C¶
Insert a child at index and return it.
- Parameters:
- Returns:
Element or str – The inserted child.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1)) >>> _ = g.insert(0, svg.rect(0, 0, 1, 1)) >>> [c.tag for c in g] ['rect', 'circle']
- property iri: IRI¶
#idpointing at this element, assigning an id if needed.Use it where SVG expects a plain IRI (
xlink:hrefof<use>,<mpath>, …); passing the element itself does the same. An element’s ownxlink:hrefisel.href.See also
urlThe
url(#id)form.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1, id="a").iri.svg_value() '#a'
- iter(tag: str | None = None, *, max_depth: float = inf) Iterator[Element]¶
Depth-first walk over this element and its descendants.
- Parameters:
- Yields:
Element – Elements in document order, starting with this one.
Examples
>>> import svgwriter as svg >>> g = svg.group(svg.circle(0, 0, 1), svg.rect(0, 0, 1, 1)) >>> [e.tag for e in g.iter()] ['g', 'circle', 'rect']
- property label: str | None¶
A readable name for the element, stored as
inkscape:label, or None.Inkscape shows it in its Layers and Objects panels, and
doc["name"]finds an element by label when no id matches. Assigning None removes it.Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> r.label = "Logo" >>> r.label, r.attributes["inkscape:label"] ('Logo', 'Logo')
- classmethod lookup(tag: str) type[Element] | None¶
Return the registered class for tag.
- Parameters:
tag (str) – An SVG tag name.
- Returns:
type[Element] or None – The class registered for the tag, or None if there is none.
Examples
>>> import svgwriter as svg >>> svg.Element.lookup("rect").__name__ 'Rect'
- classmethod many(**columns: Any) list[E]¶
Build many elements at once from columns that broadcast like numpy.
Each keyword is an attribute in Python spelling; a scalar applies to every element and an array gives one value per element. Colors may be one color, a list of colors or an
(n, 3|4)array of 0-1 floats.- Parameters:
**columns – Attribute name to scalar or sequence.
- Returns:
list of Element – The new elements, ready for
doc.group(*elements)ordoc.add_all.- Raises:
ValueError – If the columns do not broadcast to one length.
Examples
>>> import numpy as np >>> import svgwriter as svg >>> dots = svg.Circle.many(cx=np.arange(3) * 10, cy=5, r=2, fill=["red", "green", "blue"]) >>> [str(d) for d in dots][1] '<circle cx="10" cy="5" r="2" fill="green"/>'
- place(x: float, y: float, *, at: str | None = None) E¶
Move the element so its anchor, or the named point of its bounds, lands on
(x, y).- Parameters:
- Returns:
Transformable – This element.
- Raises:
ValueError – If at is not a known point name.
TypeError – If at is given and the element’s size is unknown.
See also
alignPlace relative to another element.
Examples
>>> import svgwriter as svg >>> svg.circle(0, 0, 1).place(10, 20).position Point(x=10.0, y=20.0) >>> svg.rect(0, 0, 4, 2).place(10, 10, at="bottom_right").bounds() BBox(x=6.0, y=8.0, width=4.0, height=2.0)
- property position: Point¶
The anchor in parent coordinates; assign to move the element there.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 10, 10) >>> r.position = (20, 20) >>> r.position Point(x=20.0, y=20.0)
- classmethod registered(category: Category | None = None) dict[str, type[Element]]¶
Registered element classes, optionally filtered by category.
- Parameters:
category (Category, optional) – Keep only classes of this category. Defaults to None (all).
- Returns:
dict[str, type[Element]] – Registered classes keyed by tag.
Examples
>>> import svgwriter as svg >>> "circle" in svg.Element.registered() True
- remove(child: Child) None¶
Remove a child and detach it from this element.
- Parameters:
- Raises:
ValueError – If the child is not present.
Examples
>>> import svgwriter as svg >>> c = svg.circle(0, 0, 1) >>> g = svg.group(c) >>> g.remove(c) >>> len(g) 0
- reset() E¶
Drop the transform and return
self.- Returns:
Transformable – This element.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1).translate(3, 3).reset().matrix.is_identity True
- root() Element¶
Return the topmost ancestor, or this element if it has no parent.
- Returns:
Element – The root of the tree this element belongs to.
Examples
>>> import svgwriter as svg >>> c = svg.circle(0, 0, 1) >>> g = svg.group(c) >>> c.root() is g True
- rotate(degrees: float | Angle, *, about: Pivot | None = None, local: bool = False) E¶
Rotate by degrees (clockwise on screen) and return
self.- Parameters:
degrees (float or Angle) – Angle (numbers are degrees); positive turns from +x towards +y.
about (str or (float, float), optional) – Pivot: a point name (see
anchor), read on the element’s own box, or a point in parent coordinates (local ones with local). Defaults to theanchor.local (bool, optional) – Compose in the element’s own frame. Defaults to False.
- Returns:
Transformable – This element.
- Raises:
TypeError – If degrees is a length or another non-angle quantity.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 10, 10).rotate(90).bounds() BBox(x=0.0, y=0.0, width=10.0, height=10.0) >>> svg.rect(0, 0, 10, 10).rotate(90, about="top_left").bounds() BBox(x=-10.0, y=0.0, width=10.0, height=10.0)
- save(target: AnyPath | TextSink, **options: Any) None¶
Write to a path or text stream.
- Parameters:
target (path or text stream) – Where to write the SVG markup.
**options – Serialization options, as for
to_string().
See also
to_stringSerialize to a string.
Examples
>>> import io >>> import svgwriter as svg >>> buffer = io.StringIO() >>> svg.circle(0, 0, 1).save(buffer, xml_declaration=False, pretty=False) >>> buffer.getvalue() '<circle cx="0" cy="0" r="1"/>'
- scale(sx: float, sy: float | None = None, *, about: Pivot | None = None, local: bool = False) E¶
Scale by sx and sy (default sx) about the anchor and return
self.- Parameters:
sx (float) – Factors along x and y; negative values mirror. sy defaults to sx.
sy (float) – Factors along x and y; negative values mirror. sy defaults to sx.
about (str or (float, float), optional) – Fixed point, as for
rotate(). Defaults to theanchor.local (bool, optional) – Scale along the element’s own axes instead of the parent’s. Defaults to False.
- Returns:
Transformable – This element.
Examples
>>> import svgwriter as svg >>> svg.circle(50, 50, 10).scale(2).bounds() BBox(x=30.0, y=30.0, width=40.0, height=40.0)
- set(name: str, value: AttrValue) None¶
Set one attribute;
Noneremoves it.Attributes in other namespaces use Clark notation:
"{uri}name". Colors with alpha are split into the color and its*-opacityattribute, and elements are replaced by references to them. A presentation property the inlinestylealready declares (as Inkscape writes them) is changed there, where it takes effect.- Parameters:
- Raises:
TypeError – If a length, angle or ~svgwriter.Quantity has the wrong dimension for the attribute (
widthgiven an area).ValueError – If the attribute is unsupported, a color string is not a valid color or paint, or a color with alpha is given to an attribute without an opacity counterpart.
See also
updateSet several attributes at once.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> _ = r.set("stroke_width", 3) >>> r.attributes["stroke-width"] 3 >>> styled = svg.rect(0, 0, 1, 1, style="fill:#ff0000") >>> styled.fill = "blue" >>> styled.attributes["style"], styled.has("fill") (Style({'fill': 'blue'}), False)
- skew(x_degrees: float = 0.0, y_degrees: float = 0.0, *, about: Pivot | None = None, local: bool = False) E¶
Skew along x then y by angles in degrees about the anchor and return
self.- Parameters:
x_degrees (float, optional) – Skew angles along x and y. Defaults to 0.
y_degrees (float, optional) – Skew angles along x and y. Defaults to 0.
about (str or (float, float), optional) – Fixed point, as for
rotate(). Defaults to theanchor.local (bool, optional) – Compose in the element’s own frame. Defaults to False.
- Returns:
Transformable – This element.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 10, 10).skew(45).bounds() BBox(x=-5.0, y=0.0, width=20.0, height=10.0)
- property text_content: str¶
All character data below this element, in document order (the DOM
textContent).Assigning replaces every child with the single string.
Examples
>>> import svgwriter as svg >>> t = svg.text("Hello world") >>> t[6:].fill = "red" >>> t.text_content 'Hello world' >>> title = svg.Title("Old") >>> title.text_content = "New" >>> str(title) '<title>New</title>'
- to_string(**options: Any) str¶
Serialize to an SVG string; see
svgwriter.formats.io.SerializeOptions.- Parameters:
**options – Serialization options such as
prettyorxml_declaration.- Returns:
str – The SVG markup.
See also
saveWrite to a file or stream.
Examples
>>> import svgwriter as svg >>> svg.circle(0, 0, 1).to_string(xml_declaration=False, pretty=False) '<circle cx="0" cy="0" r="1"/>'
- translate(dx: float, dy: float = 0.0, *, local: bool = False) E¶
Move by
(dx, dy)and returnself.The offset is added to the transform, in the parent frame unless local.
- Parameters:
- Returns:
Transformable – This element.
See also
placeMove the anchor to an absolute position.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 2, 2).rotate(90).translate(10, 0).position Point(x=11.0, y=1.0)
- update(attributes: Mapping[str, AttrValue] | None = None, /, **kwargs: AttrValue) None¶
Set several attributes;
Nonevalues are skipped.- Parameters:
attributes (mapping, optional) – Attributes by name. Defaults to None.
**kwargs – More attributes, Python spelling.
See also
setSet a single attribute.
Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1) >>> _ = r.update(fill="red", stroke=None) >>> r.get("fill") 'red'
- property url: FuncIRI¶
url(#id)pointing at this element, assigning an id if needed.Use it where SVG expects a functional IRI (
fill,clip-path,filter); passing the element itself does the same.See also
iriThe plain
#idform.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 1, 1, id="a").url.svg_value() 'url(#a)'
- property transform: Matrix¶
Same as
t, under the SVG attribute’s name.Examples
>>> import svgwriter as svg >>> r = svg.rect(0, 0, 1, 1).translate(2, 3) >>> r.transform == r.matrix True
- local_bbox() BBox | None[source]¶
Bounding box in local coordinates (before
t), if known.- Returns:
BBox or None – The box, or None when the element has no known extent. Subclasses override this.
Examples
>>> import svgwriter as svg >>> svg.rect(1, 2, 3, 4).local_bbox() BBox(x=1.0, y=2.0, width=3.0, height=4.0)
- class Convertible(*args: Element | str, transform: Transform | TransformOp | Matrix | str | None = None, anchor: tuple[float, float] | Point | str | None = None, **kwargs: Any)[source]¶
Bases:
TransformableConversions (
to_path,to_group,rasterize) andclip.Every conversion returns a new element or array and leaves this one unchanged. A conversion that cannot be done raises
TypeErrornaming the element and the alternatives.See also
svgwriter.model.elements.TransformableTransforms and anchors.
Examples
>>> import svgwriter as svg >>> box = svg.rect(0, 0, 10, 5, fill="red") >>> type(box.to_path()).__name__ 'Path' >>> box.rasterize().shape (5, 10, 4)
- to_path(**kwargs: Any) Path[source]¶
An equivalent
<path>.Shapes override this to return their outline; the base implementation is for elements that have none.
- Parameters:
**kwargs – Options understood by the overriding implementations.
- Returns:
Path – A new
<path>element.- Raises:
TypeError – When the element has no vector outline (an
<image>, for instance).
Examples
>>> import svgwriter as svg >>> svg.circle(5, 5, 2).to_path().tag 'path'
- to_group(**kwargs: Any) Group[source]¶
A
<g>holding a copy of this element; keywords become group attributes.A group returns a copy of itself.
- Parameters:
**kwargs – Attributes set on the group.
- Returns:
Group – A new
<g>.
Examples
>>> import svgwriter as svg >>> g = svg.circle(5, 5, 2).to_group(opacity=0.5) >>> g.tag, len(g) ('g', 1)
- to_image(*, scale: float = 1.0, padding: float = 0.0, background: ColorLike | None = None) Image[source]¶
Rasterize into an
<image>placed over this element’s bounds.- Parameters:
- Returns:
Image – Embedded pixels positioned where the element was drawn.
Examples
>>> import svgwriter as svg >>> img = svg.circle(10, 10, 5, fill="red").to_image(scale=2) >>> img.shape, (img.x, img.y, img.width) ((20, 20), (5.0, 5.0, 10.0))
- clip(*shapes: Element, units: str | None = None) E[source]¶
Clip to the union of shapes (or a
ClipPath) and returnself.Shapes are in this element’s local coordinates, so the clip moves with the element. The
<clipPath>goes into<defs>when the element is in a document.- Parameters:
*shapes (Element) – Shapes, text or
<use>; a singleClipPathis used as is.units ({"userSpaceOnUse", "objectBoundingBox"}, optional) –
clipPathUnitsfor a new clip path. Defaults to None.
- Returns:
Convertible – This element.
- Raises:
TypeError – If no shape is given.
See also
unclipRemove the clip.
Notes
to_path()(orflatten_clip()) bakes the clip into one path with a boolean intersection.Examples
>>> import svgwriter as svg >>> art = svg.rect(0, 0, 100, 100, fill="teal").clip(svg.circle(50, 50, 40)) >>> art.clip_region.tag 'clipPath'
- unclip() E[source]¶
Remove the clip and return
self.- Returns:
Convertible – This element.
Examples
>>> import svgwriter as svg >>> art = svg.rect(0, 0, 9, 9).clip(svg.circle(4, 4, 3)).unclip() >>> art.clip_region is None True
- property clip_region: ClipPath | None¶
The
<clipPath>this element is clipped by, if it can be found.Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 9, 9).clip_region is None True
- render_bounds() BBox | None[source]¶
bounds()grown by half the stroke width.- Returns:
BBox or None – The box including the stroke, or None when
bounds()is unknown.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 10, 10, stroke="black", stroke_width=2).render_bounds() BBox(x=-1.0, y=-1.0, width=12.0, height=12.0)
- rasterize(*, scale: float = 1.0, pixels: tuple[int, int] | int | None = None, padding: float = 0.0, background: ColorLike | None = None) np.ndarray[source]¶
Render this element alone into an RGBA array.
The canvas is the element’s
render_bounds()in parent coordinates, plus padding on every side.- Parameters:
scale (float, optional) – Pixels per user unit. Defaults to 1.0.
pixels ((int, int) or int, optional) – Exact output
(columns, rows), or one int for a square; the element is fitted and centred, and scale is ignored. Defaults to None.padding (float, optional) – Extra margin in user units. Defaults to 0.0.
background (color, optional) – Painted under the element. Defaults to None (transparent).
- Returns:
numpy.ndarray –
float32array, shape(rows, columns, 4), straight RGBA in0..1.- Raises:
TypeError – When the element’s size is unknown (an
<image>without width and height, for instance).
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 8, 4, fill="red").rasterize(scale=2).shape (8, 16, 4)
- class PathOperand(*children: Element | str, id: str | None = None, attrs: Mapping[str, Any] | None = None, **extra: Any)[source]¶
Bases:
BooleanOps,Measurement,AlongPath,ElementAn element with an outline.
Adds
to_path(), exact measurement, walking the outline (at(),sample(),between(),round_corners(), …) and boolean operators:a | b: uniona & b: intersectiona - b: differencea ^ b: exclusive or
Every operator returns a new
Pathcarrying the left operand’s presentation attributes.See also
svgwriter.model.elements._behavior.ConvertibleConversions and clipping.
Examples
>>> import svgwriter as svg >>> a, b = svg.rect(0, 0, 10, 10), svg.rect(5, 0, 10, 10) >>> (a | b).exact_bbox().width, (a & b).exact_bbox().width (15.0, 5.0)
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({})¶
Attributes describing the geometry; not copied by
to_path().
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- outline() PathData[source]¶
Outline in parent coordinates: clipped by
clip-path, thentapplied.- Returns:
PathData – The outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).translate(1, 1).outline()) 'M1 1 L5 1 L5 4 L1 4 Z'
- to_path(**kwargs: Any) Path[source]¶
An equivalent
<path>withtand any clip baked in.Presentation attributes are copied; keywords override them.
- Parameters:
**kwargs – Attributes set on the new path, overriding copied ones.
- Returns:
Path – A new
<path>element.
Examples
>>> import svgwriter as svg >>> svg.rect(0, 0, 4, 3, fill="red").to_path().get("fill") 'red'
- flatten_clip() Path[source]¶
The visible area as one
<path>:to_path()with the clip applied.- Returns:
Path – A new
<path>without clipping.
Examples
>>> import svgwriter as svg >>> art = svg.rect(0, 0, 10, 10).clip(svg.rect(0, 0, 5, 5)) >>> art.flatten_clip().exact_bbox().width 5.0
- expand_pattern() Element[source]¶
Replace a pattern fill by copies of its tile, clipped to this outline (plain vector graphics).
Useful for targets without pattern support (plotters, cutters, some editors). The stroke, if any, is kept on top.
- Returns:
Group – A
<g>with this element’s transform holding the clipped tiles and an unfilled copy for the stroke.- Raises:
ValueError – If
fillis not a<pattern>.
See also
svgwriter.Pattern.tilesThe tiles on their own.
Examples
>>> import svgwriter as svg >>> dots = svg.Pattern(svg.circle(2, 2, 1), width=4, height=4, pattern_units="userSpaceOnUse") >>> expanded = svg.rect(0, 0, 8, 8, fill=dots, stroke="black").expand_pattern() >>> [e.tag for e in expanded], len(expanded[0][0]) (['g', 'rect'], 4)
- transformed(transform: TransformLike) Path[source]¶
A
<path>withtand then transform baked into its coordinates.- Parameters:
transform (Transform, Matrix or str) – The transform applied after
t.- Returns:
Path – A new
<path>with no transform attribute.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 1, 1).transformed("translate(2 0)").d) 'M2 0 L3 0 L3 1 L2 1 Z'
Shapes¶
Basic shapes and <path>.
Modules¶
_base Shape and length helpers
_basic rect, circle, ellipse, line
_poly polyline, polygon
_path path
- class Circle(cx: LengthLike = 0, cy: LengthLike = 0, r: LengthLike | None = None, *, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Shape<circle>: a circle from its center and radius.- Parameters:
- Raises:
TypeError – If r is not given (
circle needs r).
See also
EllipseDifferent horizontal and vertical radii.
Examples
>>> import svgwriter as svg >>> str(svg.Circle(5, 5, 3)) '<circle cx="5" cy="5" r="3"/>'
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({'cx', 'cy', 'r'})¶
Attributes describing the geometry; not copied by
to_path().
- cx¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- cy¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- r¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- classmethod from_bbox(box: BBox, **kwargs: Any) Self[source]¶
Create the largest circle centered in a bounding box.
- Parameters:
box (BBox) – The area to fit.
**kwargs
Presentation
spelling. (core and other SVG attributes in Python)
- Returns:
Circle – The new circle.
Examples
>>> import svgwriter as svg >>> str(svg.Circle.from_bbox(svg.BBox(0, 0, 10, 20))) '<circle cx="5" cy="10" r="5"/>'
- property area: float¶
Enclosed area in square user units.
Examples
>>> import svgwriter as svg >>> round(svg.Circle(0, 0, 1).area, 4) 3.1416
- property bbox: BBox¶
Geometric bounding box in user units.
Examples
>>> import svgwriter as svg >>> svg.Circle(0, 0, 2).bbox BBox(x=-2.0, y=-2.0, width=4.0, height=4.0)
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Ellipse(cx: LengthLike = 0, cy: LengthLike = 0, rx: LengthLike | None = None, ry: LengthLike | None = None, *, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Shape<ellipse>: an ellipse from its center and two radii.- Parameters:
cx (length, optional) – Center. Defaults to 0.
cy (length, optional) – Center. Defaults to 0.
rx (length) – Horizontal and vertical radii; required, by position or as
rx=andry=.ry (length) – Horizontal and vertical radii; required, by position or as
rx=andry=.**kwargs – Presentation, core and other SVG attributes in Python spelling.
- Raises:
TypeError – If rx or ry is not given (
ellipse needs rx).
See also
CircleEqual radii.
Examples
>>> import svgwriter as svg >>> str(svg.Ellipse(5, 5, 3, 2)) '<ellipse cx="5" cy="5" rx="3" ry="2"/>'
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({'cx', 'cy', 'rx', 'ry'})¶
Attributes describing the geometry; not copied by
to_path().
- cx¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- cy¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- rx¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- ry¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- classmethod from_bbox(box: BBox, **kwargs: Any) Self[source]¶
Create the ellipse inscribed in a bounding box.
- Parameters:
box (BBox) – The area to fill.
**kwargs
Presentation
spelling. (core and other SVG attributes in Python)
- Returns:
Ellipse – The new ellipse.
Examples
>>> import svgwriter as svg >>> str(svg.Ellipse.from_bbox(svg.BBox(0, 0, 10, 20))) '<ellipse cx="5" cy="10" rx="5" ry="10"/>'
- property bbox: BBox¶
Geometric bounding box in user units.
Examples
>>> import svgwriter as svg >>> svg.Ellipse(5, 5, 3, 2).bbox BBox(x=2.0, y=3.0, width=6.0, height=4.0)
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Line(x1: LengthLike = 0, y1: LengthLike = 0, x2: LengthLike = 0, y2: LengthLike = 0, *, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Shape<line>: a straight segment between two points.- Parameters:
See also
PolylineSeveral connected segments.
Examples
>>> import svgwriter as svg >>> str(svg.Line(0, 0, 3, 4)) '<line x1="0" y1="0" x2="3" y2="4"/>'
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({'x1', 'x2', 'y1', 'y2'})¶
Attributes describing the geometry; not copied by
to_path().
- x1¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- y1¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- x2¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- y2¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- property length: float¶
Distance between the end points in user units.
Examples
>>> import svgwriter as svg >>> svg.Line(0, 0, 3, 4).length 5.0
- property bbox: BBox¶
Geometric bounding box in user units.
Examples
>>> import svgwriter as svg >>> svg.Line(0, 0, 3, 4).bbox BBox(x=0.0, y=0.0, width=3.0, height=4.0)
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Path(d: PathDataLike | PathBuilder = '', *, path_length: float | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PathCommands,Shape<path>: an arbitrary outline described by path data.Drawing methods append commands to
dand return the path, so paths can be built fluently, and paths combine with the operators ofPathOperand.- Parameters:
d (str, PathData, PathBuilder or iterable of commands, optional) – The path data. Defaults to an empty path.
path_length (float, optional) – Author’s computed total length. Defaults to None.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
PolylineStraight segments from a point array.
svgwriter.PathBuilderBuild path data without an element.
Notes
p1 + p2appendsp2’s subpaths to a copy ofp1;p += p2does it in place, as do|=,&=,-=and^=for the boolean operations.Drawing methods append to
dand return the path, so a path can be built fluently:path().move_to(0, 0).line_to(10, 0).close().Examples
>>> import svgwriter as svg >>> str(svg.Path().move_to(0, 0).line_to(10, 0).arc_to(5, 5, 10, 10).close().d) 'M0 0 L10 0 A5 5 0 0 1 10 10 Z' >>> a = svg.Path("M0 0 H10", stroke="red") >>> str(a + svg.Path("M0 5 H10")) '<path d="M0 0 H10 M0 5 H10" stroke="red"/>'
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({'d', 'pathLength'})¶
Attributes describing the geometry; not copied by
to_path().
- path_length¶
Expose one SVG attribute as a Python attribute.
- Parameters:
See also
LengthAttrAttribute that reads lengths.
Examples
>>> import svgwriter as svg >>> svg.Rect.width.key 'width' >>> svg.Rect(width=3, height=1).width 3.0
- property connects: Connection | None¶
The objects this path joins as an Inkscape connector, or None for a plain path.
Assign
(start, end)to attach the path to two elements (inkscape:connection-startand-end; it is redrawn as a straight line between their centres), or None to detach it.Examples
>>> import svgwriter as svg >>> doc = svg.Document(100, 40) >>> a, b = doc.circle(10, 20, 5), doc.circle(90, 20, 5) >>> wire = doc.path(stroke="black") >>> wire.connects = (a, b) >>> wire.connects.start is a, str(wire.d) (True, 'M10 20 L90 20')
- property d: PathData¶
The path data; assign a string,
PathDataor builder.Examples
>>> import svgwriter as svg >>> p = svg.Path("M0 0 L10 0") >>> p.d = "M5 5 H20" >>> str(p) '<path d="M5 5 H20"/>'
- property nodes: ndarray¶
All end and control points as an
(N, 2)array; assign to move them.Assigning rewrites
din absolute form. Broadcasting works as in numpy:p.nodes = p.nodes * [1, -1] + 5.Examples
>>> import svgwriter as svg >>> p = svg.Path("M0 0 L10 0 L10 10") >>> p.nodes = p.nodes + [1, 2] >>> str(p.d) 'M1 2 L11 2 L11 12'
- classmethod from_points(points: Iterable[tuple[float, float]], *, closed: bool = False, **kwargs: Any) Self[source]¶
Create a path through a sequence of points.
- Parameters:
- Returns:
Path – The new path.
See also
PolylineThe same outline as a
<polyline>.
Examples
>>> import svgwriter as svg >>> str(svg.Path.from_points([(0, 0), (5, 0), (5, 5)], closed=True)) '<path d="M0 0 L5 0 L5 5 Z"/>'
- property bbox: BBox¶
Geometric bounding box of the path data; empty paths give a zero box.
Examples
>>> import svgwriter as svg >>> svg.Path("M0 0 L10 5").bbox BBox(x=0.0, y=0.0, width=10.0, height=5.0)
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Polygon(points: PointsLike | str = (), *, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Polyline<polygon>: a closedPolyline.Takes the same parameters as
Polyline; the last vertex joins the first.- Parameters:
points (array-like or str, optional) – Vertices as
(N, 2)pairs or SVG points text. Defaults to no points.**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
PolylineThe open variant.
Examples
>>> import svgwriter as svg >>> str(svg.Polygon([(0, 0), (4, 0), (4, 3)])) '<polygon points="0,0 4,0 4,3"/>'
- property area: float¶
Enclosed area from the shoelace formula, in square user units.
Examples
>>> import svgwriter as svg >>> svg.Polygon([(0, 0), (4, 0), (4, 3)]).area 6.0
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Polyline(points: PointsLike | str = (), *, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Shape<polyline>: an open sequence of straight segments.- Parameters:
points (array-like or str, optional) – Vertices as
(N, 2)pairs or SVG points text. Defaults to no points.**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
PolygonThe closed variant.
Path.from_pointsThe same outline as a
<path>.
Examples
>>> import svgwriter as svg >>> str(svg.Polyline([(0, 0), (1, 2)])) '<polyline points="0,0 1,2"/>'
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({'points'})¶
Attributes describing the geometry; not copied by
to_path().
- property points: ndarray¶
Vertices as a read-only
(N, 2)float array.Assign any
(N, 2)array-like or SVG points text to replace them.Examples
>>> import svgwriter as svg >>> line = svg.Polyline("0,0 1,2") >>> line.points.tolist() [[0.0, 0.0], [1.0, 2.0]] >>> line.points = [(5, 5), (6, 6)] >>> str(line) '<polyline points="5,5 6,6"/>'
- classmethod regular(cx: float, cy: float, radius: float, sides: int = 6, **kwargs: Any) Self[source]¶
Create the vertices of a regular polygon.
The first vertex is at the top and the rest follow clockwise.
- Parameters:
- Returns:
Polyline – The new element; on
Polygonit is closed.
Examples
>>> import svgwriter as svg >>> str(svg.Polygon.regular(0, 0, 10, 4)) '<polygon points="0,-10 10,0 0,10 -10,0"/>'
- property bbox: BBox¶
Geometric bounding box of the vertices; no points give a zero box.
Examples
>>> import svgwriter as svg >>> svg.Polyline([(0, 0), (4, 3)]).bbox BBox(x=0.0, y=0.0, width=4.0, height=3.0)
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Rect(x: LengthLike = 0, y: LengthLike = 0, width: LengthLike | None = None, height: LengthLike | None = None, *, rx: LengthLike | None = None, ry: LengthLike | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
RectConstructors,Shape<rect>: an axis-aligned rectangle with optional rounded corners.Giving only one of rx and ry uses it for both, and radii are clamped to half the width and height, as SVG specifies.
- Parameters:
x (length, optional) – Top-left corner. Defaults to 0.
y (length, optional) – Top-left corner. Defaults to 0.
width (length) – Size; required, by position or as
width=andheight=.height (length) – Size; required, by position or as
width=andheight=.rx (length, optional) – Corner radii. Defaults to None.
ry (length, optional) – Corner radii. Defaults to None.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
- Raises:
TypeError – If width or height is not given (
rect needs width).
Examples
>>> import svgwriter as svg >>> str(svg.Rect(1, 2, 3, 4, rx=1)) '<rect x="1" y="2" width="3" height="4" rx="1"/>'
- geometry_attributes: ClassVar[frozenset[str]] = frozenset({'height', 'rx', 'ry', 'width', 'x', 'y'})¶
Attributes describing the geometry; not copied by
to_path().
- x¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- y¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- width¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- height¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- rx¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- ry¶
reads a
floatwhen unitless, aLengthwhen it has a unit.Takes the same parameters as Attr. Values that cannot be parsed as a length are returned unchanged.
See also
AttrThe general attribute descriptor.
Examples
>>> import svgwriter as svg >>> svg.Rect(width=5, height=1).width, svg.parse('<rect width="2mm"/>').width (5.0, Length(value=2.0, unit=<Unit.MM: 'mm'>))
- Type:
A length attribute
- property bbox: BBox¶
Geometric bounding box in user units.
Examples
>>> import svgwriter as svg >>> svg.Rect(1, 2, 3, 4).bbox BBox(x=1.0, y=2.0, width=3.0, height=4.0)
- corner_radii() tuple[float, float][source]¶
Return the effective corner radii.
A missing radius takes the other’s value, and each is clamped to half the corresponding side.
- Returns:
tuple of float – The effective
(rx, ry)in user units.
Examples
>>> import svgwriter as svg >>> svg.Rect(0, 0, 10, 10, rx=20).corner_radii() (5.0, 5.0)
- local_outline() PathData[source]¶
Outline in the element’s own coordinates (
tand clipping ignored).- Returns:
PathData – The outline; subclasses override this.
- Raises:
TypeError – If the element has no outline.
Examples
>>> import svgwriter as svg >>> str(svg.rect(0, 0, 4, 3).local_outline()) 'M0 0 H4 V3 H0 Z'
- class Shape(*args: Element | str, transform: Transform | TransformOp | Matrix | str | None = None, anchor: tuple[float, float] | Point | str | None = None, **kwargs: Any)[source]¶
Bases:
PathOperand,GraphicsElement,ABCBase class for the basic shapes and paths.
Every shape converts to a
<path>(to_path()) and supports the geometric operators ofPathOperand.- Parameters:
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
PathThe general shape, built from path data.
Examples
>>> import svgwriter as svg >>> str(svg.Rect(0, 0, 10, 5).to_path()) '<path d="M0 0 H10 V5 H0 Z"/>'
- abstract property bbox: BBox¶
Geometric bounding box in user units, ignoring stroke and transform.
Examples
>>> import svgwriter as svg >>> svg.Circle(5, 5, 3).bbox BBox(x=2.0, y=2.0, width=6.0, height=6.0)
- local_bbox() BBox[source]¶
Bounding box in local coordinates (before
t), if known.- Returns:
BBox or None – The box, or None when the element has no known extent. Subclasses override this.
Examples
>>> import svgwriter as svg >>> svg.rect(1, 2, 3, 4).local_bbox() BBox(x=1.0, y=2.0, width=3.0, height=4.0)
Structure and images¶
Structural, descriptive and external-content elements.
- class A(*children: Child, href: str | Element | None = None, target: str | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PathOperand,GraphicsElement,XLinkAttributes,GraphicsContainer<a>: a hyperlink around graphics.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.A(svg.Rect(0, 0, 5, 5), href="https://example.com")) '<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://example.com"><rect x="0" y="0" width="5" height="5"/></a>'
- local_bbox() BBox | None[source]¶
Box around the link’s children.
- Returns:
BBox or None – The union of the children’s bounding boxes, or None when empty.
Examples
>>> import svgwriter as svg >>> svg.A(svg.rect(0, 0, 5, 5), href="#x").local_bbox() BBox(x=0.0, y=0.0, width=5.0, height=5.0)
- class ColorProfile(name: str, href: str | None = None, *, local: str | None = None, rendering_intent: str | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,CoreAttributes<color-profile>: an ICC profile referenced byicc-color.- Parameters:
name (str) – Name used to refer to the profile from
icc-color.href (str, optional) – Location of the profile. Defaults to None.
local (str, optional) – Name of a locally installed profile. Defaults to None.
rendering_intent (str, optional) – Rendering intent, such as
"perceptual". Defaults to None.**kwargs – Presentation, core and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.ColorProfile("sRGB", "srgb.icc")) '<color-profile xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="srgb.icc" name="sRGB"/>'
- class Defs(*args: Child, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
GraphicsElement,GraphicsContainer<defs>: referenced, never directly rendered, content.- Parameters:
*children (Element) – Initial content.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
UseInstantiate an element defined here.
Examples
>>> import svgwriter as svg >>> str(svg.Defs(svg.Circle(5, 5, 3, id="dot"))) '<defs><circle id="dot" cx="5" cy="5" r="3"/></defs>'
- class Desc(text: str = '', *, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_Descriptive<desc>: a long description.- Parameters:
text (str, optional) – The description text. Defaults to empty.
**kwargs – Style, core and other SVG attributes in Python spelling.
See also
TitleA short, tooltip-style description.
Examples
>>> import svgwriter as svg >>> str(svg.Desc("A red square")) '<desc>A red square</desc>'
- class Group(*args: Child, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PathOperand,GraphicsElement,GraphicsContainer<g>: groups elements to share attributes and a transform.- Parameters:
*children (Element) – Initial content.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
SvgA group that also establishes a viewport.
Examples
>>> import svgwriter as svg >>> str(svg.Group(svg.Rect(0, 0, 5, 5), fill="red")) '<g fill="red"><rect x="0" y="0" width="5" height="5"/></g>'
- local_bbox() BBox | None[source]¶
Box around the group’s children.
- Returns:
BBox or None – The union of the children’s bounding boxes, or None when empty.
Examples
>>> import svgwriter as svg >>> svg.Group(svg.rect(0, 0, 5, 5), svg.rect(10, 10, 5, 5)).local_bbox() BBox(x=0.0, y=0.0, width=15.0, height=15.0)
- class Image(source: np.ndarray | str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, *, alpha: np.ndarray | float | None = None, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
GraphicsElement,XLinkAttributes,Positioned<image>: embedded pixels (numpy) or a linked file.- Parameters:
source (array, str or None, optional) – A pixel array (
(H, W),(H, W, 3)or(H, W, 4); floats in0..1oruint8) to embed, or a URL/path to link. Defaults to None.x (length, optional) – Top-left corner. Defaults to None.
y (length, optional) – Top-left corner. Defaults to None.
width (length, optional) – Display size; defaults to the pixel size for embedded images.
height (length, optional) – Display size; defaults to the pixel size for embedded images.
alpha (array or float, optional) – Separate alpha, broadcastable to
(H, W). Defaults to None.preserve_aspect_ratio (PreserveAspectRatio or str, optional) – How the pixels fit the box. Defaults to None.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
Image.openEmbed an image file.
PixelsThe pixel container behind an embedded image.
Notes
colorisfloat32(H, W, C)(Cis 1 for grayscale, else 3) andalphais the scalar1.0when fully opaque, otherwise(H, W, 1), socolor * alphaalways broadcasts. Edit them in place or assign new arrays. Pixels are written as a PNGdata:URI.Examples
>>> import numpy as np >>> import svgwriter as svg >>> img = svg.Image(np.zeros((2, 3, 3)), x=10) >>> img.shape, img.width, img.alpha ((2, 3), 3.0, 1.0) >>> img.color[..., 0] = 1.0 >>> img.rgba()[0, 0].tolist() [1.0, 0.0, 0.0, 1.0]
- classmethod open(path: str | PathLike[str], **kwargs: Any) Image[source]¶
Decode an image file into an embedded
<image>.- Parameters:
path (str or os.PathLike) – A PNG, JPEG, WebP, GIF or BMP file.
**kwargs – Attributes for the image, as in the constructor.
- Returns:
Image – An image holding the decoded pixels, sized to match them unless width and height are given.
- Raises:
ValueError – If the file cannot be decoded.
Examples
>>> import os, tempfile >>> import numpy as np >>> import svgwriter as svg >>> with tempfile.TemporaryDirectory() as folder: ... name = os.path.join(folder, "pixel.png") ... _ = open(name, "wb").write(svg.Image(np.zeros((2, 3, 3))).encode()) ... svg.Image.open(name).shape (2, 3)
- property pixels: Pixels | None¶
The embedded
Pixels, or None for a linked image.A
data:URI read from a document is decoded on first use.Examples
>>> import svgwriter as svg >>> svg.Image("photo.png").pixels is None True
- property color: ndarray¶
Color channels,
float32(H, W, 1|3)in0..1; editable in place.Assign an array to replace them.
Examples
>>> import numpy as np >>> import svgwriter as svg >>> img = svg.Image(np.zeros((1, 2, 3))) >>> img.color = np.ones((1, 2, 3)) >>> float(img.color.min()) 1.0
- property alpha: ndarray | float¶
1.0when opaque, elsefloat32(H, W, 1).Assign a scalar or an array broadcastable to
(H, W)to replace it.Examples
>>> import numpy as np >>> import svgwriter as svg >>> img = svg.Image(np.zeros((2, 2, 3))) >>> img.alpha = 0.5 >>> img.alpha.shape (2, 2, 1)
- Type:
Alpha
- property shape: tuple[int, int]¶
Pixel
(rows, columns).Examples
>>> import numpy as np >>> import svgwriter as svg >>> svg.Image(np.zeros((2, 3))).shape (2, 3)
- rgba() ndarray[source]¶
Combine color and alpha into one array.
- Returns:
numpy.ndarray –
(H, W, 4)float32straight (unpremultiplied) RGBA.- Raises:
TypeError – If the image links to a file rather than embedding pixels.
Examples
>>> import numpy as np >>> import svgwriter as svg >>> svg.Image(np.zeros((1, 1, 3))).rgba().tolist() [[[0.0, 0.0, 0.0, 1.0]]]
- encode(format: str = 'png', *, quality: int = 90) bytes[source]¶
Encode the pixels as an image file.
- Parameters:
format ({"png", "jpeg", "webp", "bmp", "gif", "ppm"}, optional) – Output format. Defaults to
"png".quality (int, optional) – Compression quality for lossy formats; ignored by BMP, GIF and PPM. Defaults to 90.
- Returns:
bytes – The encoded file contents.
- Raises:
TypeError – If the image links to a file rather than embedding pixels.
Examples
>>> import numpy as np >>> import svgwriter as svg >>> svg.Image(np.zeros((2, 2, 3))).encode("jpeg")[0] 255
- local_bbox() BBox | None[source]¶
Box from the
x,y,widthandheightattributes.- Returns:
BBox or None – The image rectangle, or None when it has no size.
Examples
>>> import svgwriter as svg >>> svg.Image(width=4, height=3).local_bbox() BBox(x=0.0, y=0.0, width=4.0, height=3.0) >>> svg.Image().local_bbox() is None True
- class Pixels(color: ndarray | None, alpha: ndarray | float = 1.0, source: str | None = None)[source]¶
Bases:
PixelCompositing,DrawableImage data: color channels plus a broadcastable alpha.
coloris(H, W, C)withCin {1, 3} andalphabroadcasts to it. Both arefloat32in0..1. A fully opaque image keepsalphaas the scalar1.0. Written as a PNGdata:URI.- Parameters:
color (numpy.ndarray or None) –
float32(H, W, 1|3)color channels; None when the pixels are still an undecodeddata:URI.alpha (numpy.ndarray or float, optional) – Opacity,
1.0or an array broadcastable tocolor. Defaults to 1.0.source (str, optional) – The
data:URI to decode lazily when color is None. Defaults to None.
See also
ImageThe
<image>element holding pixels.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> Pixels.from_array(np.zeros((2, 3, 3))) Pixels(2x3, channels=3, opaque=True)
- classmethod from_array(array: object, alpha: object = None) Pixels[source]¶
Create pixels from an array, splitting off any embedded alpha channel.
- Parameters:
array (array-like) –
(H, W)or(H, W, 1|2|3|4)values, floats in0..1oruint8. Two and four channels carry alpha last.alpha (array-like or float, optional) – Separate alpha broadcastable to
(H, W). Defaults to None.
- Returns:
Pixels – The color and alpha as
float32arrays.- Raises:
ValueError – If the shape is unsupported, float values leave
0..1, or alpha is given both in array and as alpha.TypeError – If the array is not numeric.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> px = Pixels.from_array(np.zeros((1, 2, 4))) >>> px.color.shape, px.alpha.shape ((1, 2, 3), (1, 2, 1))
- classmethod decode(data: bytes, *, profile: bytes | str | None = None, intent: str | None = None) Pixels[source]¶
Decode encoded image bytes into sRGB.
Embedded colour information (ICC profile, PNG
gAMA/cHRM) is applied, so the pixels look as the file intends. ICC profiles go through LittleCMS.- Parameters:
data (bytes) – PNG, JPEG, WebP, GIF, BMP or PNM file contents.
profile (bytes or str, optional) – The
color-profileof the image: ICC profile bytes that replace any embedded profile,"sRGB"to read the stored values as sRGB, or"auto"(the default, also None) to use the embedded profile.intent (str, optional) – SVG
rendering-intentfor a profile conversion, such as"relative-colorimetric". Defaults to perceptual.
- Returns:
Pixels – The decoded pixels.
- Raises:
ValueError – If the data is damaged or in an unknown format, or profile is an unknown keyword.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> png = Pixels.from_array(np.zeros((2, 2, 3))).encode() >>> Pixels.decode(png) Pixels(2x2, channels=3, opaque=True)
- property color: ndarray¶
Color channels,
float32(H, W, 1|3)in0..1; editable in place.Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> pixels = Pixels.from_array(np.zeros((2, 3, 3))) >>> pixels.color.shape (2, 3, 3)
- property alpha: ndarray | float¶
1.0when opaque, elsefloat32(H, W, 1).Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> Pixels.from_array(np.zeros((2, 3, 3))).alpha 1.0 >>> Pixels.from_array(np.zeros((2, 3, 3)), alpha=0.5).alpha.shape (2, 3, 1)
- Type:
Alpha
- property shape: tuple[int, int]¶
Pixel
(rows, columns).Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> Pixels.from_array(np.zeros((2, 3, 3))).shape (2, 3)
- rgba() ndarray[source]¶
Combine color and alpha into one array.
- Returns:
numpy.ndarray –
(H, W, 4)float32straight (unpremultiplied) RGBA; grayscale is expanded to three channels.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> Pixels.from_array(np.ones((1, 1))).rgba().tolist() [[[1.0, 1.0, 1.0, 1.0]]]
- clone() Pixels[source]¶
Copy the pixel arrays.
- Returns:
Pixels – An independent copy; editing it leaves this one unchanged.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> px = Pixels.from_array(np.zeros((1, 1, 3))) >>> px.clone() == px True
- encode(format: str = 'png', *, quality: int = 90) bytes[source]¶
Encode the pixels as an image file.
- Parameters:
format ({"png", "jpeg", "webp", "bmp", "gif", "ppm"}, optional) – Output format. Defaults to
"png".quality (int, optional) – Compression quality for lossy formats; ignored by BMP, GIF and PPM. Defaults to 90.
- Returns:
bytes – The encoded file contents.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> Pixels.from_array(np.zeros((2, 2, 3))).encode()[1:4] b'PNG'
- svg_value(precision: int = 4) str[source]¶
Serialize as a
data:URI.- Parameters:
precision (int, optional) – Unused; present for the attribute-value protocol. Defaults to the library default.
- Returns:
str – A base64 PNG
data:URI, or the original URI if never decoded.
Examples
>>> import numpy as np >>> from svgwriter.model.elements.structure import Pixels >>> Pixels.from_array(np.zeros((1, 1, 3))).svg_value()[:30] 'data:image/png;base64,iVBORw0K'
- class Metadata(*children: Child, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes<metadata>: arbitrary content, usually RDF in a foreign namespace.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.Metadata("licensed")) '<metadata>licensed</metadata>'
- class StyleElement(css: str | StyleSheet = '', *, type: str = 'text/css', media: str | None = None, title: str | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes<style>: an embedded style sheet.- Parameters:
css (str or StyleSheet, optional) – The style sheet text, or a
StyleSheetto render. Defaults to empty.type (str, optional) – Style language. Defaults to
"text/css".media (str, optional) – Media query the sheet applies to. Defaults to None.
title (str, optional) – Alternate style sheet title. Defaults to None.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.StyleElement("circle { fill: red }")) '<style type="text/css">circle { fill: red }</style>'
- class Svg(*children: Child, version: str | None = '1.1', base_profile: str | None = None, zoom_and_pan: str | None = None, content_style_type: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, view_box: ViewBoxLike | None = None, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Positioned,FitToViewBox,ExternalResourcesAttribute,PresentationAttributes,ConditionalAttributes,CoreAttributes,GraphicsContainer<svg>: a document root or nested viewport.- Parameters:
*children (Element) – Initial content.
version (str, optional) – Written as the
versionattribute;Noneomits it. Defaults to the SVG version the library targets ("1.1").base_profile (str, optional) – The remaining
<svg>-specific attributes. Defaults to None.zoom_and_pan (str, optional) – The remaining
<svg>-specific attributes. Defaults to None.content_style_type (str, optional) – The remaining
<svg>-specific attributes. Defaults to None.**kwargs – Position (
x,y,width,height),view_box, presentation, conditional and core attributes in Python spelling.
See also
Examples
>>> import svgwriter as svg >>> str(svg.Svg(svg.Circle(5, 5, 3), width=10, height=10)) '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" version="1.1"><circle cx="5" cy="5" r="3"/></svg>'
- classmethod with_size(width: float, height: float, **kwargs: Any) Self[source]¶
Create a root with a size and a matching viewBox.
- Parameters:
- Returns:
Svg – The new root.
Examples
>>> import svgwriter as svg >>> str(svg.Svg.with_size(100, 50)) '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="50" viewBox="0 0 100 50" version="1.1"/>'
- defs() Defs[source]¶
Return the first
<defs>child, creating one if needed.A new
<defs>is inserted before all other children.- Returns:
Defs – The existing or newly created
<defs>.
Examples
>>> import svgwriter as svg >>> doc = svg.Svg() >>> doc.defs() is doc.defs() True >>> str(doc) '<svg xmlns="http://www.w3.org/2000/svg" version="1.1"><defs/></svg>'
- class Switch(*args: Child, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PathOperand,GraphicsElement,GraphicsContainer<switch>: renders the first child whose conditions pass.- Parameters:
*children (Element) – Initial content.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.Switch(svg.Rect(0, 0, 5, 5, required_extensions="x"))) '<switch><rect x="0" y="0" width="5" height="5" requiredExtensions="x"/></switch>'
- local_bbox() BBox | None[source]¶
Box around the switch’s children.
- Returns:
BBox or None – The union of the children’s bounding boxes, or None when empty.
Examples
>>> import svgwriter as svg >>> svg.Switch(svg.rect(0, 0, 5, 5)).local_bbox() BBox(x=0.0, y=0.0, width=5.0, height=5.0)
- class Symbol(*args: Child, view_box: ViewBoxLike | None = None, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FitToViewBox,ExternalResourcesAttribute,PresentationAttributes,CoreAttributes,GraphicsContainer<symbol>: a template instantiated by<use>.- Parameters:
*children (Element) – Initial content.
**kwargs –
view_box,preserve_aspect_ratio, presentation and core attributes in Python spelling.
See also
UseInstantiate the symbol.
Examples
>>> import svgwriter as svg >>> str(svg.Symbol(svg.Circle(5, 5, 3), id="dot", view_box=(0, 0, 10, 10))) '<symbol id="dot" viewBox="0 0 10 10"><circle cx="5" cy="5" r="3"/></symbol>'
- class Title(text: str = '', *, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_Descriptive<title>: a short, tooltip-style description.- Parameters:
text (str, optional) – The title text. Defaults to empty.
**kwargs – Style, core and other SVG attributes in Python spelling.
See also
DescA longer description.
Examples
>>> import svgwriter as svg >>> str(svg.Title("Square")) '<title>Square</title>'
- class Use(href: str | Element | None = None, x: LengthLike | None = None, y: LengthLike | None = None, *, width: LengthLike | None = None, height: LengthLike | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
UseGeometry,PathOperand,GraphicsElement,XLinkAttributes,Positioned<use>: renders a referenced element.- Parameters:
href (str or Element, optional) – The target as a reference string or the element itself, which gets an id if it has none. Defaults to None.
x (length, optional) – Translation applied to the instance. Defaults to None.
y (length, optional) – Translation applied to the instance. Defaults to None.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> dot = svg.Circle(5, 5, 3, id="dot") >>> str(svg.Use(dot, x=10)) '<use xmlns:xlink="http://www.w3.org/1999/xlink" x="10" xlink:href="#dot"/>'
- class View(*, view_target: str | None = None, zoom_and_pan: str | None = None, view_box: ViewBoxLike | None = None, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FitToViewBox,ExternalResourcesAttribute,CoreAttributes<view>: a named view into the document.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.View(id="zoomed", view_box=(0, 0, 50, 50))) '<view id="zoomed" viewBox="0 0 50 50"/>'
Text and fonts¶
Text content elements, live character handles and SVG fonts.
- class AltGlyph(text: str = '', *, href: str | Element | None = None, glyph_ref: str | None = None, format: str | None = None, x: Coordinates | None = None, y: Coordinates | None = None, dx: Coordinates | None = None, dy: Coordinates | None = None, rotate: float | Sequence[float] | None = None, decoration: TextDecoration | str | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,PresentationAttributes,ConditionalAttributes,CoreAttributes,_TextPositioning<altGlyph>: substitute glyphs for its character data.- Parameters:
text (str, optional) – The character data to substitute. Defaults to the empty string.
href (str or Element, optional) – An
altGlyphDefor a glyph, or its IRI.glyph_ref (str, optional) – Identifier of the glyph in the referenced font.
format (str, optional) – Glyph format of the font.
x (length or sequence of length, optional) – Absolute and relative positions.
y (length or sequence of length, optional) – Absolute and relative positions.
dx (length or sequence of length, optional) – Absolute and relative positions.
dy (length or sequence of length, optional) – Absolute and relative positions.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
AltGlyphDefThe definition
hrefpoints at.
Examples
>>> str(AltGlyph("a", glyph_ref="g1")) '<altGlyph glyphRef="g1">a</altGlyph>'
- class AltGlyphDef(*args: Child, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes,Container[Element]<altGlyphDef>: glyph substitutions foraltGlyph.- Parameters:
*children (Element) – Either one sequence of
GlyphRefor severalAltGlyphItem.**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
AltGlyphThe element that uses the definition.
Examples
>>> len(AltGlyphDef(AltGlyphItem(GlyphRef("#a")))) 1
- class AltGlyphItem(*args: Child, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes,Container[GlyphRef]<altGlyphItem>: one candidate set of glyph references.- Parameters:
*children (GlyphRef) – The glyph references of the candidate.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
AltGlyphDefThe container of candidates.
Examples
>>> len(AltGlyphItem(GlyphRef("#a"), GlyphRef("#b"))) 2
- class Character(text: Text, index: int, start: int | None = None, stop: int | None = None)[source]¶
Bases:
_CharactersA live handle on character index of a
<text>(text[i]).- Parameters:
Notes
Moves and rotations edit the text’s
dx/dy/rotatelists, so the result is still selectable SVG text. Scale and skew have no per-character form in SVG; useText.glyphs()for outlines that can be transformed freely.Examples
>>> import svgwriter as svg >>> t = svg.text("abc", x=0, y=10) >>> t[1].translate(0, -4).rotate(20) Character('b', 1) >>> t.dy, t.rotate_ ((0.0, -4.0, 4.0), (0.0, 20.0, 0.0))
- property index: int¶
Zero-based index of the character in the text.
Examples
>>> import svgwriter as svg >>> svg.text("abc", x=0, y=10)[2].index 2
- property char: str¶
The character itself.
Examples
>>> import svgwriter as svg >>> svg.text("abc", x=0, y=10)[1].char 'b'
- class CharacterRange(text: Text, start: int, stop: int)[source]¶
Bases:
_CharactersA live handle on characters
[start, stop)of a<text>(text[a:b]).Setting a presentation attribute on the range wraps it in a styled
<tspan>.- Parameters:
Examples
>>> import svgwriter as svg >>> t = svg.text("Hello world", x=0, y=20) >>> t[6:11].fill = "red" >>> str(t) '<text x="0" y="20">Hello <tspan fill="red">world</tspan></text>'
- class CharacterSelection(ranges: Sequence[CharacterRange])[source]¶
Bases:
objectCharacters picked by a list, a mask or a stepped slice, as contiguous
CharacterRangeruns.Setting a presentation attribute sets it on every run, so each run becomes a styled
<tspan>.- Parameters:
ranges (sequence of CharacterRange) – The runs, in text order.
Examples
>>> import svgwriter as svg >>> t = svg.text("Hello", x=0, y=20) >>> t[[0, 1, 4]].fill = "red" >>> str(t) '<text x="0" y="20"><tspan fill="red">He</tspan>ll<tspan fill="red">o</tspan></text>' >>> t[[True, False, True, False, True]].chars 'Hlo'
- fill: PaintValue¶
- stroke: PaintValue¶
- stroke_width: LengthLike¶
- font_size: LengthLike¶
- letter_spacing: LengthLike¶
- classmethod of(text: Text, positions: Sequence[int], bounds: Sequence[int]) CharacterSelection[source]¶
The selection of character positions (cluster indices) of text.
- effect(name: str, /, **options: Any) CharacterSelection[source]¶
Apply an effect from
svg.effectsto every run and return the selection.
- ranges¶
- class Font(*children: Child, horiz_adv_x: float = 0, horiz_origin_x: float | None = None, horiz_origin_y: float | None = None, vert_origin_x: float | None = None, vert_origin_y: float | None = None, vert_adv_y: float | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FontGlyphs,PresentationAttributes,ExternalResourcesAttribute,CoreAttributes,Container[Element]<font>: an SVG font made of glyph outlines.This is the SVG 1.1 element; to set text in TrueType/OpenType font files, use
Typeface.- Parameters:
*children (Element) – Glyphs, kerning pairs and a
font-face.horiz_adv_x (float, optional) – Default horizontal advance of glyphs. Defaults to 0.
horiz_origin_x (float, optional) – Origin for horizontal text.
horiz_origin_y (float, optional) – Origin for horizontal text.
vert_origin_x (float, optional) – Origin for vertical text.
vert_origin_y (float, optional) – Origin for vertical text.
vert_adv_y (float, optional) – Default vertical advance of glyphs.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
Examples
>>> f = Font(horiz_adv_x=10) >>> str(f) '<font horiz-adv-x="10"/>'
- class FontFace(*children: Child, font_family: str | None = None, font_style: str | None = None, font_variant: str | None = None, font_weight: str | None = None, font_stretch: str | None = None, font_size: str | None = None, unicode_range: str | None = None, units_per_em: float | None = None, ascent: float | None = None, descent: float | None = None, cap_height: float | None = None, x_height: float | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **descriptors: Any)[source]¶
Bases:
CoreAttributes,Container[Element]<font-face>: font descriptors, mirroring CSS@font-face.Less common descriptors (
panose_1,v_alphabetic,underline_positionand so on) go through**descriptors.- Parameters:
*children (Element) – A
font-face-srcand similar.font_family (str, optional) – The matching CSS descriptors.
font_style (str, optional) – The matching CSS descriptors.
font_variant (str, optional) – The matching CSS descriptors.
font_weight (str, optional) – The matching CSS descriptors.
font_stretch (str, optional) – The matching CSS descriptors.
font_size (str, optional) – The matching CSS descriptors.
unicode_range (str, optional) – Characters the face covers.
units_per_em (float, optional) – The em square in glyph units.
ascent (float, optional) – Vertical metrics in glyph units.
descent (float, optional) – Vertical metrics in glyph units.
cap_height (float, optional) – Vertical metrics in glyph units.
x_height (float, optional) – Vertical metrics in glyph units.
**descriptors – Further descriptors and core attributes in Python spelling.
See also
FontFaceSrcWhere the font data comes from.
Examples
>>> str(FontFace(font_family="X", units_per_em=1000)) '<font-face font-family="X" units-per-em="1000"/>'
- class FontFaceFormat(string: str | None = None, *, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes<font-face-format>: the format of afont-face-uri.- Parameters:
string (str, optional) – The format hint, such as
"svg".**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
FontFaceUriThe element it describes.
Examples
>>> str(FontFaceFormat("svg")) '<font-face-format string="svg"/>'
- class FontFaceName(name: str | None = None, *, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes<font-face-name>: a locally installed font by name.- Parameters:
name (str, optional) – The font’s name.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
FontFaceUriAn external font instead.
Examples
>>> str(FontFaceName("X")) '<font-face-name name="X"/>'
- class FontFaceSrc(*args: Child, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes,Container[Element]<font-face-src>: where the font data comes from.- Parameters:
*children (Element) –
FontFaceUriandFontFaceNameentries, in order of preference.**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
FontFaceThe descriptor element that contains it.
Examples
>>> str(FontFaceSrc(FontFaceName("X"))) '<font-face-src><font-face-name name="X"/></font-face-src>'
- class FontFaceUri(href: str | None = None, *formats: FontFaceFormat, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,CoreAttributes,Container[FontFaceFormat]<font-face-uri>: an external font reference.- Parameters:
href (str, optional) – Location of the font.
*formats (FontFaceFormat) – Format hints.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
FontFaceNameA locally installed font instead.
Examples
>>> len(FontFaceUri("a.svg", FontFaceFormat("svg"))) 1
- class Glyph(unicode: str | None = None, d: PathData | PathBuilder | str | None = None, *, glyph_name: str | None = None, orientation: str | None = None, arabic_form: str | None = None, lang: str | None = None, horiz_adv_x: float | None = None, vert_origin_x: float | None = None, vert_origin_y: float | None = None, vert_adv_y: float | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_GlyphBase<glyph>: the outline for one character sequence.- Parameters:
unicode (str, optional) – The character sequence the glyph draws.
d (PathData or PathBuilder or str, optional) – The outline.
glyph_name (str, optional) – A name to refer to the glyph by.
orientation (str, optional) –
"h"or"v"to restrict the glyph to one writing direction.arabic_form (str, optional) – Contextual form for Arabic.
lang (str, optional) – Language the glyph applies to.
**kwargs –
horiz_adv_x,vert_origin_x,vert_origin_y,vert_adv_yand other presentation, core and SVG attributes in Python spelling.
See also
MissingGlyphThe fallback glyph.
Examples
>>> str(Glyph("a", "M0 0L5 5", horiz_adv_x=6)) '<glyph d="M0 0 L5 5" horiz-adv-x="6" unicode="a"/>'
- class GlyphRef(href: str | Element | None = None, *, glyph_ref: str | None = None, format: str | None = None, x: float | None = None, y: float | None = None, dx: float | None = None, dy: float | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,PresentationAttributes,CoreAttributes<glyphRef>: one glyph of analtGlyphDef.- Parameters:
glyph_ref (str, optional) – Identifier of the glyph in the font.
format (str, optional) – Glyph format of the font.
x (float, optional) – Position and offset of the glyph.
y (float, optional) – Position and offset of the glyph.
dx (float, optional) – Position and offset of the glyph.
dy (float, optional) – Position and offset of the glyph.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
AltGlyphItemGroups glyph references into one candidate set.
Examples
>>> GlyphRef("#g", x=1).get("x") 1
- class HKern(k: float, *, u1: str | None = None, g1: str | None = None, u2: str | None = None, g2: str | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_Kern<hkern>: horizontal kerning pair.- Parameters:
k (float) – The adjustment applied between the pair.
u1 (str, optional) – Unicode characters or ranges of the first and second glyph.
u2 (str, optional) – Unicode characters or ranges of the first and second glyph.
g1 (str, optional) – Glyph names of the first and second glyph.
g2 (str, optional) – Glyph names of the first and second glyph.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
VKernVertical kerning.
Examples
>>> str(HKern(-3, u1="A", u2="V")) '<hkern u1="A" u2="V" k="-3"/>'
- class MissingGlyph(*children: Child, d: PathData | PathBuilder | str | None = None, horiz_adv_x: float | None = None, vert_origin_x: float | None = None, vert_origin_y: float | None = None, vert_adv_y: float | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_GlyphBase<missing-glyph>: drawn for characters without a glyph.- Parameters:
*children (Element) – Graphics, as an alternative to
d.d (PathData or PathBuilder or str, optional) – The outline.
horiz_adv_x (float, optional) – Horizontal advance.
vert_origin_x (float, optional) – Origin for vertical text.
vert_origin_y (float, optional) – Origin for vertical text.
vert_adv_y (float, optional) – Vertical advance.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
GlyphA glyph for a specific character.
Examples
>>> str(MissingGlyph(d="M0 0")) '<missing-glyph d="M0 0"/>'
- class TRef(href: str | Element | None = None, *, x: Coordinates | None = None, y: Coordinates | None = None, dx: Coordinates | None = None, dy: Coordinates | None = None, rotate: float | Sequence[float] | None = None, decoration: TextDecoration | str | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,PresentationAttributes,ConditionalAttributes,CoreAttributes,_TextPositioning<tref>: the character data of a referenced element.- Parameters:
href (str or Element, optional) – The referenced element, or its IRI.
x (length or sequence of length, optional) – Absolute and relative positions.
y (length or sequence of length, optional) – Absolute and relative positions.
dx (length or sequence of length, optional) – Absolute and relative positions.
dy (length or sequence of length, optional) – Absolute and relative positions.
rotate (float or sequence of float, optional) – Per-character rotation in degrees.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
TSpanA run with its own character data.
Examples
>>> TRef("#label", x=1).get("x") 1
- class TSpan(*args: Child, text_length: LengthLike | None = None, length_adjust: LengthAdjust | None = None, x: Coordinates | None = None, y: Coordinates | None = None, dx: Coordinates | None = None, dy: Coordinates | None = None, rotate: float | Sequence[float] | None = None, decoration: TextDecoration | str | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PresentationAttributes,ConditionalAttributes,CoreAttributes,_TextLength,_TextPositioning<tspan>: a sub-run of text with its own position or style.- Parameters:
x (length or sequence of length, optional) – Absolute and relative positions.
y (length or sequence of length, optional) – Absolute and relative positions.
dx (length or sequence of length, optional) – Absolute and relative positions.
dy (length or sequence of length, optional) – Absolute and relative positions.
rotate (float or sequence of float, optional) – Per-character rotation in degrees.
text_length (length, optional) – Target advance width of the run.
length_adjust ({"spacing", "spacingAndGlyphs"}, optional) – How
text_lengthis met.decoration (TextDecoration, optional) – Written as
text-decoration.**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
Text.spanAppend a span to a text.
Examples
>>> str(TSpan("a", dx=3, fill="red")) '<tspan dx="3" fill="red">a</tspan>'
- class Text(*args: Child, text_length: LengthLike | None = None, length_adjust: LengthAdjust | None = None, x: Coordinates | None = None, y: Coordinates | None = None, dx: Coordinates | None = None, dy: Coordinates | None = None, rotate: float | Sequence[float] | None = None, decoration: TextDecoration | str | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
TextAccess,PathOperand,GraphicsElement,_TextLength,_TextPositioning<text>: a run of graphics text, laid out with the installed fonts.The element holds character data and nested
tspan,tref,textPathandaltGlyphchildren. Characters can be addressed, moved and outlined individually.- Parameters:
*content (str or Element) – Text runs and
tspan/tref/textPath/altGlyphchildren.x (length or sequence of length, optional) – Absolute and relative positions; a list positions successive characters.
y (length or sequence of length, optional) – Absolute and relative positions; a list positions successive characters.
dx (length or sequence of length, optional) – Absolute and relative positions; a list positions successive characters.
dy (length or sequence of length, optional) – Absolute and relative positions; a list positions successive characters.
rotate (float or sequence of float, optional) – Per-character rotation in degrees.
text_length (length, optional) – Target advance width of the text.
length_adjust ({"spacing", "spacingAndGlyphs"}, optional) – How
text_lengthis met.decoration (TextDecoration, optional) – Written as
text-decoration.**kwargs – Presentation, core and other SVG attributes in Python spelling.
Notes
Text takes part in boolean operations through its glyph outlines (
Rect(0, 0, 100, 40) - Text("Hi", ...)).text[i]is a liveCharacterfor character i (len(text)counts characters);glyphs()returns one outline path per character. The methodrotate()rotates the whole element; the per-character SVGrotatelist istext.rotate_.Examples
>>> str(Text("Hi", x=10, y=20, decoration=TextDecoration.UNDERLINE)) '<text x="10" y="20" text-decoration="underline">Hi</text>'
- class TextDecoration(*values)[source]¶
Bases:
FlagThe
text-decorationkeywords, combinable with|.Pass a member (or a combination) as the
decorationargument ofText,TSpanorAltGlyph.See also
TextThe element that takes the
decorationargument.
Examples
>>> d = TextDecoration.UNDERLINE | TextDecoration.LINE_THROUGH >>> d.svg_value() 'underline line-through'
- NONE = 0¶
- UNDERLINE = 1¶
- OVERLINE = 2¶
- LINE_THROUGH = 4¶
- BLINK = 8¶
- svg_value(precision: int = 4) str[source]¶
Format the flags as a
text-decorationattribute value.- Parameters:
precision (int, optional) – Unused; accepted so every attribute value shares one signature. Defaults to the library’s default precision.
- Returns:
str – The space-separated keywords, or
"none"when no flag is set.
Examples
>>> TextDecoration.NONE.svg_value() 'none' >>> TextDecoration.OVERLINE.svg_value() 'overline'
- class TextPath(*content: Child, href: str | Element | None = None, start_offset: LengthLike | None = None, method: str | None = None, spacing: str | None = None, text_length: LengthLike | None = None, length_adjust: LengthAdjust | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,PresentationAttributes,ConditionalAttributes,CoreAttributes,_TextLength<textPath>: text laid out along a path.- Parameters:
href (str or Element, optional) – The path to follow, or its IRI.
start_offset (length, optional) – Distance along the path where the text starts.
method ({"align", "stretch"}, optional) – How glyphs are fitted to the path.
spacing ({"auto", "exact"}, optional) – How glyph spacing is computed.
text_length (length, optional) – Target advance width of the text.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
TextText laid out on a straight baseline.
Examples
>>> TextPath("abc", href="#p", start_offset="50%").get("startOffset") '50%'
- class VKern(k: float, *, u1: str | None = None, g1: str | None = None, u2: str | None = None, g2: str | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_Kern<vkern>: vertical kerning pair.- Parameters:
k (float) – The adjustment applied between the pair.
u1 (str, optional) – Unicode characters or ranges of the first and second glyph.
u2 (str, optional) – Unicode characters or ranges of the first and second glyph.
g1 (str, optional) – Glyph names of the first and second glyph.
g2 (str, optional) – Glyph names of the first and second glyph.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
HKernHorizontal kerning.
Examples
>>> str(VKern(2, u1="a", u2="b")) '<vkern u1="a" u2="b" k="2"/>'
Paint servers, clipping and markers¶
Paint servers, clipping and markers: gradients, stops, patterns, clipPath, mask and marker.
- class ClipPath(*children: Child, clip_path_units: Units | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PathOperand,Transformable,PresentationAttributes,ConditionalAttributes,ExternalResourcesAttribute,CoreAttributes,GraphicsContainer<clipPath>: shapes whose union is the clipping region.- Parameters:
*children (Element) – Shapes, text and
useelements that define the region.clip_path_units ({"userSpaceOnUse", "objectBoundingBox"}, optional) – Coordinate system of the content.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
MaskSoft, luminance-based masking.
Examples
>>> import svgwriter as svg >>> str(ClipPath(svg.Rect(0, 0, 10, 10), id="c")) '<clipPath id="c"><rect x="0" y="0" width="10" height="10"/></clipPath>'
- local_bbox() BBox | None[source]¶
Box around the clipping shapes.
- Returns:
BBox or None –
Nonewhen the clip path is empty.
Examples
>>> import svgwriter as svg >>> ClipPath(svg.Rect(0, 0, 10, 20)).local_bbox().height 20.0
- class Gradient(*stops: Stop, gradient_units: Literal['userSpaceOnUse', 'objectBoundingBox'] | None = None, spread_method: Literal['pad', 'reflect', 'repeat'] | None = None, **kwargs: Any)[source]¶
Bases:
GradientStops,Transformable,XLinkAttributes,ExternalResourcesAttribute,PresentationAttributes,CoreAttributes,Container[Stop]Shared base of linear and radial gradients.
Holds the color stops and the attributes common to both kinds.
- Parameters:
*stops (Stop) – Color stops.
gradient_units ({"objectBoundingBox", "userSpaceOnUse"}, optional) – Coordinate system of the gradient vector. Defaults to None.
spread_method ({"pad", "reflect", "repeat"}, optional) – What happens beyond the ends of the vector. Defaults to None.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
LinearGradientGradient along a line.
RadialGradientGradient around a center.
Examples
>>> import svgwriter as svg >>> grad = svg.LinearGradient(svg.Stop(0, "red"), svg.Stop(1, "blue")) >>> isinstance(grad, svg.Gradient), len(grad) (True, 2)
- class LinearGradient(*stops: Stop, x1: LengthLike | None = None, y1: LengthLike | None = None, x2: LengthLike | None = None, y2: LengthLike | None = None, gradient_units: Units | None = None, spread_method: SpreadMethod | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Gradient<linearGradient>: a gradient along a line.- Parameters:
*stops (Stop) – Color stops.
x1 (length, optional) – The gradient vector.
y1 (length, optional) – The gradient vector.
x2 (length, optional) – The gradient vector.
y2 (length, optional) – The gradient vector.
gradient_units ({"objectBoundingBox", "userSpaceOnUse"}, optional) – Coordinate system of the vector.
spread_method ({"pad", "reflect", "repeat"}, optional) – What happens beyond the ends of the vector.
**kwargs –
transform,hrefand other presentation, core and SVG attributes in Python spelling.
See also
RadialGradientGradient around a center.
Examples
>>> str(LinearGradient(Stop(0, "red"), x2=1)) '<linearGradient x2="1"><stop offset="0" stop-color="red"/></linearGradient>'
- local_bbox() BBox | None[source]¶
Box spanned by the gradient vector.
- Returns:
BBox or None – The unit box for
objectBoundingBoxunits, otherwise the box around the vector’s end points.
Examples
>>> LinearGradient(x1=0, y1=0, x2=10, y2=5, gradient_units="userSpaceOnUse").local_bbox().width 10.0
- classmethod horizontal(*colors: Color | str, **kwargs: Any) Self[source]¶
Create an evenly spaced left-to-right gradient.
- Parameters:
- Returns:
LinearGradient – A gradient from
(0, 0)to(1, 0)in bounding-box units.
Examples
>>> LinearGradient.horizontal("red", "blue").get("x2") 1
- class Marker(*children: Child, ref_x: float = 0, ref_y: float = 0, marker_width: LengthLike | None = None, marker_height: LengthLike | None = None, marker_units: Literal['strokeWidth', 'userSpaceOnUse'] | None = None, orient: MarkerOrient | None = None, view_box: ViewBoxLike | None = None, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FitToViewBox,PresentationAttributes,ExternalResourcesAttribute,CoreAttributes,GraphicsContainer<marker>: arrowheads and other symbols at path vertices.- Parameters:
*children (Element) – The marker graphics.
ref_x (float, optional) – The point aligned with the vertex. Defaults to 0.
ref_y (float, optional) – The point aligned with the vertex. Defaults to 0.
marker_width (length, optional) – Viewport size.
marker_height (length, optional) – Viewport size.
marker_units ({"strokeWidth", "userSpaceOnUse"}, optional) – Coordinate system of the size.
orient (float or "auto", optional) – Rotation;
"auto"follows the path direction.**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
PathA shape that can carry markers.
Examples
>>> import svgwriter as svg >>> m = Marker(svg.Circle(0, 0, 2), ref_x=1, marker_width=4, marker_height=4, orient="auto") >>> m.get("orient") 'auto'
- class Mask(*children: Child, mask_units: Units | None = None, mask_content_units: Units | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Positioned,PresentationAttributes,ConditionalAttributes,ExternalResourcesAttribute,CoreAttributes,GraphicsContainer<mask>: luminance of its content becomes the alpha mask.- Parameters:
*children (Element) – The graphics whose luminance defines the mask.
mask_units ({"objectBoundingBox", "userSpaceOnUse"}, optional) – Coordinate system of
x,y,widthandheight.mask_content_units ({"userSpaceOnUse", "objectBoundingBox"}, optional) – Coordinate system of the content.
**kwargs –
x,y,width,heightand other presentation, core and SVG attributes in Python spelling.
See also
ClipPathHard-edged clipping region.
Examples
>>> import svgwriter as svg >>> str(Mask(svg.Rect(0, 0, 10, 10), id="m", mask_units="userSpaceOnUse")) '<mask id="m" maskUnits="userSpaceOnUse"><rect x="0" y="0" width="10" height="10"/></mask>'
- class Pattern(*children: Child, pattern_units: Units | None = None, pattern_content_units: Units | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, view_box: ViewBoxLike | None = None, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PatternTiling,Transformable,Positioned,FitToViewBox,XLinkAttributes,ExternalResourcesAttribute,PresentationAttributes,ConditionalAttributes,CoreAttributes,GraphicsContainer<pattern>: a tile of graphics used as paint.- Parameters:
*children (Element) – The graphics of one tile.
pattern_units ({"objectBoundingBox", "userSpaceOnUse"}, optional) – Coordinate system of
x,y,widthandheight.pattern_content_units ({"objectBoundingBox", "userSpaceOnUse"}, optional) – Coordinate system of the tile’s content.
**kwargs –
x,y,width,height,view_box,transformand other presentation, core and SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> p = Pattern(svg.Circle(2, 2, 2), width=4, height=4, pattern_units="userSpaceOnUse") >>> p.local_bbox().width 4.0
- class RadialGradient(*stops: Stop, cx: LengthLike | None = None, cy: LengthLike | None = None, r: LengthLike | None = None, fx: LengthLike | None = None, fy: LengthLike | None = None, gradient_units: Units | None = None, spread_method: SpreadMethod | None = None, transform: TransformLike | None = None, anchor: Pivot | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
Gradient<radialGradient>: a gradient around a center.- Parameters:
*stops (Stop) – Color stops.
cx (length, optional) – Center of the outer circle.
cy (length, optional) – Center of the outer circle.
r (length, optional) – Radius of the outer circle.
fx (length, optional) – Focal point.
fy (length, optional) – Focal point.
gradient_units ({"objectBoundingBox", "userSpaceOnUse"}, optional) – Coordinate system of the circle.
spread_method ({"pad", "reflect", "repeat"}, optional) – What happens beyond the circle.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
LinearGradientGradient along a line.
Examples
>>> str(RadialGradient(cx=0.5, cy=0.5, r=0.5)) '<radialGradient cx="0.5" cy="0.5" r="0.5"/>'
- class Stop(offset: float | str = 0, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, *, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
PresentationAttributes,CoreAttributes<stop>: one color stop of a gradient.- Parameters:
offset (float or str, optional) – Position along the gradient vector, 0 to 1 or a percentage. Defaults to 0.
stop_color (Color or str, optional) – The color at the offset.
stop_opacity (float, optional) – The opacity at the offset.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
See also
Gradient.add_stopCreate and append a stop in one call.
Examples
>>> str(Stop(0.5, "red", 0.5)) '<stop offset="0.5" stop-color="red" stop-opacity="0.5"/>'
Filters¶
<filter> and every SVG 1.1 filter primitive.
- class BlendMode(*values)[source]¶
Bases:
KeywordBlend modes of
FeBlend.Examples
>>> import svgwriter as svg >>> svg.BlendMode.MULTIPLY.value 'multiply'
- NORMAL = 'normal'¶
- MULTIPLY = 'multiply'¶
- SCREEN = 'screen'¶
- DARKEN = 'darken'¶
- LIGHTEN = 'lighten'¶
- class Channel(*values)[source]¶
Bases:
KeywordColor channels selectable in
FeDisplacementMap.Examples
>>> import svgwriter as svg >>> svg.Channel.RED.value 'R'
- R = 'R'¶
- G = 'G'¶
- B = 'B'¶
- A = 'A'¶
- RED = 'R'¶
- GREEN = 'G'¶
- BLUE = 'B'¶
- ALPHA = 'A'¶
- class ColorMatrixType(*values)[source]¶
Bases:
KeywordTypes of
FeColorMatrix.Examples
>>> import svgwriter as svg >>> svg.ColorMatrixType.HUE_ROTATE.value 'hueRotate'
- MATRIX = 'matrix'¶
- SATURATE = 'saturate'¶
- HUE_ROTATE = 'hueRotate'¶
- LUMINANCE_TO_ALPHA = 'luminanceToAlpha'¶
- class CompositeOperator(*values)[source]¶
Bases:
KeywordOperators of
FeComposite.Examples
>>> import svgwriter as svg >>> svg.CompositeOperator.ATOP.value 'atop'
- OVER = 'over'¶
- IN = 'in'¶
- OUT = 'out'¶
- ATOP = 'atop'¶
- XOR = 'xor'¶
- ARITHMETIC = 'arithmetic'¶
- class EdgeMode(*values)[source]¶
Bases:
KeywordEdge handling of
FeConvolveMatrix.Examples
>>> import svgwriter as svg >>> svg.EdgeMode.WRAP.value 'wrap'
- DUPLICATE = 'duplicate'¶
- WRAP = 'wrap'¶
- NONE = 'none'¶
- class FeBlend(mode: BlendMode = BlendMode.NORMAL, *, in2: FilterInput | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
TwoInputs<feBlend>: blend two inputs with a mode.- Parameters:
mode (BlendMode, optional) – How to blend. Defaults to
BlendMode.NORMAL, which is omitted from the output.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeBlend(svg.BlendMode.MULTIPLY, in_="SourceGraphic", in2="shade")) '<feBlend in="SourceGraphic" in2="shade" mode="multiply"/>'
- class FeColorMatrix(type: ColorMatrixType = ColorMatrixType.MATRIX, values: Sequence[float] | float | None = None, *, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
ColorMatrixShortcuts,SingleInput<feColorMatrix>: a 5x4 color transform or a shorthand.- Parameters:
type (ColorMatrixType, optional) – Kind of transform. Defaults to
ColorMatrixType.MATRIX.values (sequence of float or float, optional) – The 20 matrix entries for
matrix, otherwise the single amount. Defaults to None.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
- Raises:
ValueError – If a
matrixis given other than 20 values.
See also
FeComponentTransferPer-channel remapping.
Examples
>>> import svgwriter as svg >>> str(svg.FeColorMatrix.saturate(0)) '<feColorMatrix type="saturate" values="0"/>'
- class FeComponentTransfer(*functions: FeFunc, red: FeFunc | None = None, green: FeFunc | None = None, blue: FeFunc | None = None, alpha: FeFunc | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SingleInput,Container[FeFunc]<feComponentTransfer>: per-channel remapping.- Parameters:
*functions (FeFunc) – Channel functions to add as children.
red (FeFunc, optional) – Functions for one channel each; they are converted to the matching
feFuncR/G/B/Aelement. Default to None.green (FeFunc, optional) – Functions for one channel each; they are converted to the matching
feFuncR/G/B/Aelement. Default to None.blue (FeFunc, optional) – Functions for one channel each; they are converted to the matching
feFuncR/G/B/Aelement. Default to None.alpha (FeFunc, optional) – Functions for one channel each; they are converted to the matching
feFuncR/G/B/Aelement. Default to None.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
See also
FeColorMatrixMix channels with a matrix.
Examples
>>> import svgwriter as svg >>> str(svg.FeComponentTransfer(red=svg.FeFuncR.linear(2))) '<feComponentTransfer><feFuncR type="linear" slope="2" intercept="0"/></feComponentTransfer>'
- class FeComposite(operator: CompositeOperator = CompositeOperator.OVER, *, k1: float | None = None, k2: float | None = None, k3: float | None = None, k4: float | None = None, in2: FilterInput | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
TwoInputs<feComposite>: Porter-Duff compositing or arithmetic.- Parameters:
operator (CompositeOperator, optional) – The compositing operation. Defaults to
CompositeOperator.OVER.k1 (float, optional) – Coefficients of the
arithmeticoperator. Defaults to None.k2 (float, optional) – Coefficients of the
arithmeticoperator. Defaults to None.k3 (float, optional) – Coefficients of the
arithmeticoperator. Defaults to None.k4 (float, optional) – Coefficients of the
arithmeticoperator. Defaults to None.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeComposite(svg.CompositeOperator.IN)) '<feComposite operator="in"/>'
- class FeConvolveMatrix(kernel_matrix: Sequence[float] = (), order: int | tuple[int, int] = 3, *, divisor: float | None = None, bias: float | None = None, target_x: int | None = None, target_y: int | None = None, edge_mode: EdgeMode | None = None, kernel_unit_length: float | tuple[float, float] | None = None, preserve_alpha: bool | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SingleInput<feConvolveMatrix>: apply a convolution kernel.- Parameters:
kernel_matrix (sequence of float, optional) – The kernel, row by row. Defaults to empty.
order (int or tuple of int, optional) – Kernel size, or
(columns, rows). Defaults to 3.divisor (float, optional) – Normalisation divisor and added bias. Default to None.
bias (float, optional) – Normalisation divisor and added bias. Default to None.
target_x (int, optional) – Kernel cell aligned with the output pixel. Default to None.
target_y (int, optional) – Kernel cell aligned with the output pixel. Default to None.
edge_mode (EdgeMode, optional) – Handling of pixels beyond the edge. Defaults to None.
kernel_unit_length (float or tuple of float, optional) – Kernel scale. Defaults to None.
preserve_alpha (bool, optional) – Leave the alpha channel unconvolved. Defaults to None.
**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
- Raises:
ValueError – If the kernel length does not match order.
Examples
>>> import svgwriter as svg >>> str(svg.FeConvolveMatrix([0, 1, 0, 1, -4, 1, 0, 1, 0], divisor=1)) '<feConvolveMatrix order="3" kernelMatrix="0 1 0 1 -4 1 0 1 0" divisor="1"/>'
- class FeDiffuseLighting(*light: Child, diffuse_constant: float | None = None, surface_scale: float | None = None, kernel_unit_length: float | tuple[float, float] | None = None, lighting_color: Color | str | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_Lighting<feDiffuseLighting>: Lambertian lighting of the alpha bump map.- Parameters:
*light (LightSource) – The light source child.
diffuse_constant (float, optional) – Diffuse reflection constant. Defaults to None.
surface_scale (float, optional) – Height of the surface for full alpha. Defaults to None.
kernel_unit_length (float or tuple of float, optional) – Surface normal sampling distance. Defaults to None.
lighting_color (Color or str, optional) – Color of the light. Defaults to None.
**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
See also
FeSpecularLightingSpecular highlights.
Examples
>>> import svgwriter as svg >>> str(svg.FeDiffuseLighting(svg.FeDistantLight(45, 60), surface_scale=2)) '<feDiffuseLighting surfaceScale="2"><feDistantLight azimuth="45" elevation="60"/></feDiffuseLighting>'
- class FeDisplacementMap(scale: float = 0, x_channel_selector: Channel = Channel.A, y_channel_selector: Channel = Channel.A, *, in2: FilterInput | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
TwoInputs<feDisplacementMap>: displaceinby channels ofin2.- Parameters:
scale (float, optional) – Displacement scale. Defaults to 0.
x_channel_selector (Channel, optional) – Channels of
in2driving each axis. Default toChannel.A.y_channel_selector (Channel, optional) – Channels of
in2driving each axis. Default toChannel.A.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeDisplacementMap(5, svg.Channel.R, svg.Channel.G)) '<feDisplacementMap scale="5" xChannelSelector="R" yChannelSelector="G"/>'
- class FeDistantLight(azimuth: float = 0, elevation: float = 0, *, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
LightSource<feDistantLight>: light from infinitely far away.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.FeDistantLight(45, 60)) '<feDistantLight azimuth="45" elevation="60"/>'
- property directional: bool¶
the direction is the same everywhere.
- Returns:
bool –
True.
Examples
>>> import svgwriter as svg >>> svg.FeDistantLight(45, 60).directional True
- Type:
Always
True
- light_vector(x: float, y: float, z: float) tuple[float, float, float][source]¶
The constant unit vector towards the light, independent of the point.
- Parameters:
- Returns:
tuple of float – Unit vector
(x, y, z)pointing at the light.
Examples
>>> import svgwriter as svg >>> svg.FeDistantLight(0, 0).light_vector(5, 5, 0) (1.0, 0.0, 0.0)
- class FeFlood(flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, *, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FilterPrimitive<feFlood>: fill the sub-region with a color.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.FeFlood("red", 0.5)) '<feFlood flood-color="red" flood-opacity="0.5"/>'
- class FeFunc(type: TransferType = TransferType.IDENTITY, *, table_values: Sequence[float] | None = None, slope: float | None = None, intercept: float | None = None, amplitude: float | None = None, exponent: float | None = None, offset: float | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributesShared base of the four channel transfer functions.
- Parameters:
type (TransferType, optional) – Kind of function. Defaults to
TransferType.IDENTITY.table_values (sequence of float, optional) – Lookup table for
tableanddiscrete. Defaults to None.slope (float, optional) – Coefficients of
linear. Default to None.intercept (float, optional) – Coefficients of
linear. Default to None.amplitude (float, optional) – Coefficients of
gamma. Default to None.exponent (float, optional) – Coefficients of
gamma. Default to None.offset (float, optional) – Coefficients of
gamma. Default to None.**kwargs – Core and other SVG attributes in Python spelling.
See also
FeComponentTransferThe primitive that holds these functions.
Examples
>>> import svgwriter as svg >>> str(svg.FeFuncR.linear(2, 0.1)) '<feFuncR type="linear" slope="2" intercept="0.1"/>'
- classmethod linear(slope: float, intercept: float = 0, **kwargs: Any) Self[source]¶
Create a linear transfer function,
slope * C + intercept.- Parameters:
- Returns:
FeFunc – The new function element.
Examples
>>> import svgwriter as svg >>> str(svg.FeFuncA.linear(0.5)) '<feFuncA type="linear" slope="0.5" intercept="0"/>'
- classmethod table(*values: float, **kwargs: Any) Self[source]¶
Create a piecewise-linear transfer function from lookup values.
- Parameters:
*values (float) – Table entries, evenly spaced over the input range.
**kwargs – Core and other SVG attributes in Python spelling.
- Returns:
FeFunc – The new function element.
See also
evaluateApply the function to a value.
Examples
>>> import svgwriter as svg >>> str(svg.FeFuncR.table(0, 1)) '<feFuncR type="table" tableValues="0 1"/>'
- classmethod gamma(amplitude: float = 1, exponent: float = 1, offset: float = 0, **kwargs: Any) Self[source]¶
Create a gamma transfer function,
amplitude * C ** exponent + offset.- Parameters:
- Returns:
FeFunc – The new function element.
Examples
>>> import svgwriter as svg >>> svg.FeFuncG.gamma(2, 3).evaluate(0.5) 0.25
- class FeFuncA(type: TransferType = TransferType.IDENTITY, *, table_values: Sequence[float] | None = None, slope: float | None = None, intercept: float | None = None, amplitude: float | None = None, exponent: float | None = None, offset: float | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FeFunc<feFuncA>: the transfer function of the alpha channel.Takes the parameters of
FeFunc.Examples
>>> import svgwriter as svg >>> svg.FeFuncA.tag 'feFuncA'
- class FeFuncB(type: TransferType = TransferType.IDENTITY, *, table_values: Sequence[float] | None = None, slope: float | None = None, intercept: float | None = None, amplitude: float | None = None, exponent: float | None = None, offset: float | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FeFunc<feFuncB>: the transfer function of the blue channel.Takes the parameters of
FeFunc.Examples
>>> import svgwriter as svg >>> svg.FeFuncB.tag 'feFuncB'
- class FeFuncG(type: TransferType = TransferType.IDENTITY, *, table_values: Sequence[float] | None = None, slope: float | None = None, intercept: float | None = None, amplitude: float | None = None, exponent: float | None = None, offset: float | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FeFunc<feFuncG>: the transfer function of the green channel.Takes the parameters of
FeFunc.Examples
>>> import svgwriter as svg >>> svg.FeFuncG.tag 'feFuncG'
- class FeFuncR(type: TransferType = TransferType.IDENTITY, *, table_values: Sequence[float] | None = None, slope: float | None = None, intercept: float | None = None, amplitude: float | None = None, exponent: float | None = None, offset: float | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FeFunc<feFuncR>: the transfer function of the red channel.Takes the parameters of
FeFunc.Examples
>>> import svgwriter as svg >>> str(svg.FeFuncR.table(0, 1)) '<feFuncR type="table" tableValues="0 1"/>'
- class FeGaussianBlur(std_deviation: float | tuple[float, float] = 0, *, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SingleInput<feGaussianBlur>: blur the input with a Gaussian.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.FeGaussianBlur(std_deviation=2)) '<feGaussianBlur stdDeviation="2"/>'
- class FeImage(href: str | None = None, *, preserve_aspect_ratio: PreserveAspectRatio | str | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,ExternalResourcesAttribute,FilterPrimitive<feImage>: an external image or referenced element as input.- Parameters:
href (str, optional) – URL of the image or reference to an element. Defaults to None.
preserve_aspect_ratio (PreserveAspectRatio or str, optional) – How the image fits the sub-region. Defaults to None.
**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeImage("texture.png")) '<feImage xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="texture.png"/>'
- class FeMerge(*nodes: Child | FilterInput, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FilterPrimitive,Container[FeMergeNode]<feMerge>: stack inputs withover, first at the bottom.- Parameters:
*nodes (FeMergeNode, FilterInput) – Layers, either nodes or anything accepted as an input, which is wrapped in a node.
**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeMerge(svg.FeOffset(id="shadow"), "SourceGraphic")) '<feMerge><feMergeNode in="shadow-out"/><feMergeNode in="SourceGraphic"/></feMerge>'
- class FeMergeNode(in_: FilterInput | None = None, *, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes<feMergeNode>: one layer offeMerge.- Parameters:
in (StandardInput, str or FilterPrimitive, optional) – The layer’s input. Defaults to None.
**kwargs – Core and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeMergeNode("SourceGraphic")) '<feMergeNode in="SourceGraphic"/>'
- class FeMorphology(operator: MorphologyOperator = MorphologyOperator.ERODE, radius: float | tuple[float, float] = 0, *, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SingleInput<feMorphology>: erode (thin) or dilate (fatten) the input.- Parameters:
operator (MorphologyOperator, optional) –
erodeordilate. Defaults toMorphologyOperator.ERODE.radius (float or tuple of float, optional) – Radius, or
(x, y). Defaults to 0.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeMorphology(svg.MorphologyOperator.DILATE, 2)) '<feMorphology operator="dilate" radius="2"/>'
- class FeOffset(dx: float = 0, dy: float = 0, *, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SingleInput<feOffset>: shift the input.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.FeOffset(dx=2, dy=3)) '<feOffset dx="2" dy="3"/>'
- class FePointLight(x: float = 0, y: float = 0, z: float = 0, *, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
LightSource<fePointLight>: an omnidirectional point light.- Parameters:
Examples
>>> import svgwriter as svg >>> str(svg.FePointLight(1, 2, 3)) '<fePointLight x="1" y="2" z="3"/>'
- property directional: bool¶
the direction depends on the surface point.
- Returns:
bool –
False.
Examples
>>> import svgwriter as svg >>> svg.FePointLight(1, 2, 3).directional False
- Type:
Always
False
- light_vector(x: float, y: float, z: float) tuple[float, float, float][source]¶
The unit vector from the point towards the light position.
- Parameters:
- Returns:
tuple of float – Unit vector
(x, y, z)pointing at the light.
Examples
>>> import svgwriter as svg >>> svg.FePointLight(0, 10, 0).light_vector(0, 0, 0) (0.0, 1.0, 0.0)
- class FeSpecularLighting(*light: Child, specular_constant: float | None = None, specular_exponent: float | None = None, surface_scale: float | None = None, kernel_unit_length: float | tuple[float, float] | None = None, lighting_color: Color | str | None = None, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
_Lighting<feSpecularLighting>: Phong specular highlights.- Parameters:
*light (LightSource) – The light source child.
specular_constant (float, optional) – Specular reflection constant. Defaults to None.
specular_exponent (float, optional) – Shininess exponent. Defaults to None.
surface_scale (float, optional) – Height of the surface for full alpha. Defaults to None.
kernel_unit_length (float or tuple of float, optional) – Surface normal sampling distance. Defaults to None.
lighting_color (Color or str, optional) – Color of the light. Defaults to None.
**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
See also
FeDiffuseLightingDiffuse lighting.
Examples
>>> import svgwriter as svg >>> str(svg.FeSpecularLighting(svg.FePointLight(1, 2, 3), specular_exponent=5)) '<feSpecularLighting specularExponent="5"><fePointLight x="1" y="2" z="3"/></feSpecularLighting>'
- class FeSpotLight(x: float = 0, y: float = 0, z: float = 0, *, points_at_x: float = 0, points_at_y: float = 0, points_at_z: float = 0, specular_exponent: float | None = None, limiting_cone_angle: float | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FePointLight<feSpotLight>: a point light aimed atpointsAt.- Parameters:
x (float, optional) – Light position. Defaults to 0.
y (float, optional) – Light position. Defaults to 0.
z (float, optional) – Light position. Defaults to 0.
points_at_x (float, optional) – The point the light aims at. Default to 0.
points_at_y (float, optional) – The point the light aims at. Default to 0.
points_at_z (float, optional) – The point the light aims at. Default to 0.
specular_exponent (float, optional) – Focus of the light beam. Defaults to None.
limiting_cone_angle (float, optional) – Half-angle of the cone in degrees. Defaults to None.
**kwargs – Core and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeSpotLight(1, 2, 3, points_at_x=4)) '<feSpotLight x="1" y="2" z="3" pointsAtX="4" pointsAtY="0" pointsAtZ="0"/>'
- class FeTile(*args: Child, in_: FilterInput | None = None, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SingleInput<feTile>: repeat the input’s sub-region.- Parameters:
**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeTile(in_="cell")) '<feTile in="cell"/>'
- class FeTurbulence(base_frequency: float | tuple[float, float] = 0, num_octaves: int = 1, *, seed: float | None = None, stitch_tiles: bool = False, type: TurbulenceType = TurbulenceType.TURBULENCE, result: str | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FilterPrimitive<feTurbulence>: Perlin noise.- Parameters:
base_frequency (float or tuple of float, optional) – Noise frequency, or
(x, y). Defaults to 0.num_octaves (int, optional) – Number of noise layers. Defaults to 1.
seed (float, optional) – Random seed. Defaults to None.
stitch_tiles (bool, optional) – Stitch tile edges seamlessly. Defaults to False.
type (TurbulenceType, optional) –
turbulenceorfractalNoise. Defaults toTurbulenceType.TURBULENCE.**kwargs – Sub-region (
x,y,width,height),result,in_and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeTurbulence(0.05, 2, seed=1)) '<feTurbulence baseFrequency="0.05" numOctaves="2" seed="1" type="turbulence"/>'
- class Filter(*primitives: Child, filter_units: Units | None = None, primitive_units: Units | None = None, filter_res: float | tuple[float, float] | None = None, x: LengthLike | None = None, y: LengthLike | None = None, width: LengthLike | None = None, height: LengthLike | None = None, fill: PaintValue = None, fill_opacity: Opacity | None = None, fill_rule: FillRule | None = None, stroke: PaintValue = None, stroke_width: LengthLike | None = None, stroke_opacity: Opacity | None = None, stroke_linecap: LineCap | None = None, stroke_linejoin: LineJoin | None = None, stroke_miterlimit: float | None = None, stroke_dasharray: Sequence[float] | str | None = None, stroke_dashoffset: LengthLike | None = None, opacity: Opacity | None = None, display: str | None = None, visibility: str | None = None, color: str | None = None, clip_path: str | Element | None = None, mask: str | Element | None = None, filter: str | Element | None = None, font_family: str | None = None, font_size: LengthLike | None = None, font_weight: str | int | None = None, text_anchor: str | None = None, alignment_baseline: str | None = None, baseline_shift: LengthLike | str | None = None, clip: str | None = None, clip_rule: FillRule | None = None, color_interpolation: str | None = None, color_interpolation_filters: str | None = None, color_profile: str | None = None, color_rendering: str | None = None, direction: str | None = None, dominant_baseline: str | None = None, enable_background: str | None = None, flood_color: Color | str | None = None, flood_opacity: Opacity | None = None, font: Typeface | str | None = None, font_size_adjust: float | str | None = None, font_stretch: str | None = None, font_style: str | None = None, font_variant: str | None = None, glyph_orientation_horizontal: float | str | None = None, glyph_orientation_vertical: float | str | None = None, image_rendering: str | None = None, kerning: LengthLike | str | None = None, letter_spacing: LengthLike | str | None = None, lighting_color: Color | str | None = None, marker: str | Element | None = None, marker_end: str | Element | None = None, marker_mid: str | Element | None = None, marker_start: str | Element | None = None, overflow: str | None = None, pointer_events: str | None = None, shape_rendering: str | None = None, stop_color: Color | str | None = None, stop_opacity: Opacity | None = None, text_decoration: TextDecoration | str | None = None, text_rendering: str | None = None, unicode_bidi: str | None = None, word_spacing: LengthLike | str | None = None, writing_mode: str | None = None, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,Positioned,PresentationAttributes,ExternalResourcesAttribute,CoreAttributes,Container[Element]<filter>: a graph of filter primitives.- Parameters:
*primitives (FilterPrimitive) – The primitives, in evaluation order.
filter_units ({"userSpaceOnUse", "objectBoundingBox"}, optional) – Coordinate systems for the region and the primitives.
primitive_units ({"userSpaceOnUse", "objectBoundingBox"}, optional) – Coordinate systems for the region and the primitives.
filter_res (float or (float, float), optional) – Intermediate image resolution.
**kwargs – Region (
x,y,width,height),hrefand presentation/core attributes in Python spelling.
See also
FilterPrimitiveBase of the elements a filter contains.
Examples
>>> import svgwriter as svg >>> str(svg.Filter(svg.FeGaussianBlur(std_deviation=1), id="soft")) '<filter id="soft"><feGaussianBlur stdDeviation="1"/></filter>'
- collect() Self[source]¶
Insert every detached primitive the filter’s primitives read, before its first reader.
Filter(merge)is then enough: the blur and offset that feed the merge come along in dependency order.- Returns:
Filter – This filter, for chaining.
Examples
>>> import svgwriter as svg >>> blur = svg.FeGaussianBlur(3, in_="SourceAlpha") >>> shadow = svg.FeOffset(2, 2, in_=blur) >>> f = svg.Filter(svg.FeMerge(shadow, "SourceGraphic")) >>> [p.tag for p in f.primitives] ['feGaussianBlur', 'feOffset', 'feMerge']
- property primitives: list[FilterPrimitive]¶
The filter-primitive children in evaluation order.
Examples
>>> import svgwriter as svg >>> svg.Filter(svg.FeOffset(), svg.FeTile()).primitives [<FeOffset feOffset dx='0' dy='0'>, <FeTile feTile>]
- class FilterPrimitive(*args: Element | str, result: str | None = None, **kwargs: Any)[source]¶
Bases:
Positioned,PresentationAttributes,CoreAttributesBase of every
fe*element: sub-region andresultname.- Parameters:
See also
FilterThe container that holds primitives.
Examples
>>> import svgwriter as svg >>> str(svg.FeOffset(result="shifted")) '<feOffset result="shifted" dx="0" dy="0"/>'
- property result: str¶
The result name, generated on first access if unset.
Examples
>>> import svgwriter as svg >>> svg.FeOffset(id="shift").result 'shift-out'
- sources() list[FilterPrimitive][source]¶
The primitives this one reads, directly or through merge nodes, nearest first.
- Returns:
list of FilterPrimitive – Every upstream primitive given as an input object (not by name).
Examples
>>> import svgwriter as svg >>> blur = svg.FeGaussianBlur(2, in_="SourceAlpha") >>> shifted = svg.FeOffset(2, 2, in_=blur) >>> shifted.sources() == [blur] True
- class LightSource(*args: Element | str, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, **kwargs: Any)[source]¶
Bases:
CoreAttributes,ABCAbstract light source; the child of a lighting primitive.
- Parameters:
**kwargs – Core and other SVG attributes in Python spelling.
See also
FeDistantLightLight from infinitely far away.
FePointLightA point light.
Examples
>>> import svgwriter as svg >>> svg.FeDistantLight(0, 0).directional True
- abstract property directional: bool¶
Truewhen the light direction is the same everywhere.Examples
>>> import svgwriter as svg >>> svg.FePointLight().directional False
- abstractmethod light_vector(x: float, y: float, z: float) tuple[float, float, float][source]¶
Compute the direction from a surface point towards the light.
- Parameters:
- Returns:
tuple of float – Unit vector
(x, y, z)pointing at the light.
Examples
>>> import svgwriter as svg >>> svg.FePointLight(0, 0, 10).light_vector(0, 0, 0) (0.0, 0.0, 1.0)
- class MorphologyOperator(*values)[source]¶
Bases:
KeywordOperators of
FeMorphology.Examples
>>> import svgwriter as svg >>> svg.MorphologyOperator.DILATE.value 'dilate'
- ERODE = 'erode'¶
- DILATE = 'dilate'¶
- class SingleInput(*args: Element | str, in_: StandardInput | str | FilterPrimitive | None = None, **kwargs: Any)[source]¶
Bases:
FilterPrimitivePrimitives that read one input (
in).- Parameters:
*args (Element) – Initial children.
in (StandardInput, str or FilterPrimitive, optional) – The input: a keyword, a result name or the primitive producing it. Defaults to None, meaning the previous primitive’s result.
**kwargs –
result, sub-region and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeOffset(in_="SourceAlpha")) '<feOffset in="SourceAlpha" dx="0" dy="0"/>'
- class StandardInput(*values)[source]¶
Bases:
KeywordKeywords accepted by
inandin2.Examples
>>> import svgwriter as svg >>> svg.StandardInput.SOURCE_ALPHA.value 'SourceAlpha'
- SOURCE_GRAPHIC = 'SourceGraphic'¶
- SOURCE_ALPHA = 'SourceAlpha'¶
- BACKGROUND_IMAGE = 'BackgroundImage'¶
- BACKGROUND_ALPHA = 'BackgroundAlpha'¶
- FILL_PAINT = 'FillPaint'¶
- STROKE_PAINT = 'StrokePaint'¶
- class TransferType(*values)[source]¶
Bases:
KeywordTransfer function types of
FeFunc.Examples
>>> import svgwriter as svg >>> svg.TransferType.GAMMA.value 'gamma'
- IDENTITY = 'identity'¶
- TABLE = 'table'¶
- DISCRETE = 'discrete'¶
- LINEAR = 'linear'¶
- GAMMA = 'gamma'¶
- class TurbulenceType(*values)[source]¶
Bases:
KeywordNoise types of
FeTurbulence.Examples
>>> import svgwriter as svg >>> svg.TurbulenceType.FRACTAL_NOISE.value 'fractalNoise'
- FRACTAL_NOISE = 'fractalNoise'¶
- TURBULENCE = 'turbulence'¶
- class TwoInputs(*args: Element | str, in2: StandardInput | str | FilterPrimitive | None = None, **kwargs: Any)[source]¶
Bases:
SingleInputPrimitives that combine
inandin2.- Parameters:
*args (Element) – Initial children.
in2 (StandardInput, str or FilterPrimitive, optional) – The second input. Defaults to None.
**kwargs –
in_,result, sub-region and other SVG attributes in Python spelling.
Examples
>>> import svgwriter as svg >>> str(svg.FeBlend(in_="SourceGraphic", in2="shade")) '<feBlend in="SourceGraphic" in2="shade"/>'
- resolve_input(value: StandardInput | str | FilterPrimitive | None) StandardInput | str | None[source]¶
Turn a primitive into the name of its result.
Referring to a primitive by element lets its
resultname be generated on demand; keywords and strings pass through unchanged.- Parameters:
value (StandardInput, str, FilterPrimitive or None) – An input keyword, a result name or the primitive producing the input.
- Returns:
StandardInput, str or None – The result name for a primitive, otherwise value itself.
Examples
>>> import svgwriter as svg >>> svg.resolve_input(svg.FeOffset(id="shift")) 'shift-out' >>> svg.resolve_input("SourceAlpha") 'SourceAlpha'
Animation¶
SMIL animation elements (animate, set, animateMotion, mpath, animateColor,
animateTransform) and their timing curve, Ease.
- class Accumulate(*values)[source]¶
Bases:
KeywordThe
accumulateattribute: whether repeats build on the previous end value.See also
AdditiveControls combination with the underlying value.
Examples
>>> Accumulate.NONE.value 'none'
- NONE = 'none'¶
- SUM = 'sum'¶
- class Additive(*values)[source]¶
Bases:
KeywordThe
additiveattribute: replace the underlying value or add to it.See also
AccumulateRepeat-iteration counterpart.
Examples
>>> Additive.SUM.value 'sum'
- REPLACE = 'replace'¶
- SUM = 'sum'¶
- class Animate(*args: Child, begin: Clock | None = None, dur: Clock | None = None, end: Clock | None = None, min: Clock | None = None, max: Clock | None = None, restart: Restart | None = None, repeat_count: RepeatCount | None = None, repeat_dur: Clock | None = None, fill: AnimationFill | None = None, values: Sequence[Any] | str | None = None, from_: Any = None, to: Any = None, by: Any = None, calc_mode: CalcMode | None = None, key_times: Sequence[float] | str | None = None, key_splines: Sequence[tuple[float, float, float, float]] | str | None = None, additive: Additive | None = None, accumulate: Accumulate | None = None, ease: EaseLike | None = None, attribute_name: str | None = None, attribute_type: Literal['CSS', 'XML', 'auto'] | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
FadeShortcut,AnimationElement,_ValueAnimation,_AttributeTarget<animate>: interpolate one attribute over time.- Parameters:
attribute_name (str, optional) – The attribute to animate.
attribute_type ({"CSS", "XML", "auto"}, optional) – Namespace of the attribute.
values (sequence or str, optional) – The values to pass through.
from (object, optional) – Start value (written
from).to (object, optional) – End value.
by (object, optional) – Relative change.
calc_mode (CalcMode, optional) – Interpolation mode.
key_times (sequence of float or str, optional) – Times of each value, 0 to 1.
key_splines (sequence of 4-tuples or str, optional) – Bezier control points for spline mode.
additive (Additive, optional) – Combination with the underlying value.
accumulate (Accumulate, optional) – Whether repeats accumulate.
ease (str, tuple, callable or Ease, optional) – Timing curve over the whole timeline (see
Ease); setscalcMode,keyTimesandkeySplines(or samplesvalues), so leavecalc_modeunset or"linear"/"discrete".**kwargs – Timing (
begin,dur,repeat_countand so on, seeAnimationElement), core and other SVG attributes.
See also
SetAssign a value instead of interpolating.
AnimateTransformAnimate the
transformattribute.
Examples
>>> str(Animate.fade(1, 0, dur=2)) '<animate attributeName="opacity" from="1" to="0" dur="2s"/>' >>> str(Animate(attribute_name="x", from_=0, to=90, dur=1, ease="ease-in-out")) '<animate attributeName="x" from="0" to="90" calcMode="spline" keyTimes="0;1" keySplines="0.42 0 0.58 1" dur="1s"/>'
- class AnimateColor(*args: Child, begin: Clock | None = None, dur: Clock | None = None, end: Clock | None = None, min: Clock | None = None, max: Clock | None = None, restart: Restart | None = None, repeat_count: RepeatCount | None = None, repeat_dur: Clock | None = None, fill: AnimationFill | None = None, values: Sequence[Any] | str | None = None, from_: Any = None, to: Any = None, by: Any = None, calc_mode: CalcMode | None = None, key_times: Sequence[float] | str | None = None, key_splines: Sequence[tuple[float, float, float, float]] | str | None = None, additive: Additive | None = None, accumulate: Accumulate | None = None, ease: EaseLike | None = None, attribute_name: str | None = None, attribute_type: Literal['CSS', 'XML', 'auto'] | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
AnimationElement,_ValueAnimation,_AttributeTarget<animateColor>: color interpolation (deprecated in later SVG).Takes the same parameters as
Animate.See also
AnimatePreferred, as it also interpolates colors.
Examples
>>> str(AnimateColor(attribute_name="fill", from_="red", to="blue")) '<animateColor attributeName="fill" from="red" to="blue"/>'
- class AnimateMotion(*children: Child, path: PathData | PathBuilder | str | None = None, key_points: Sequence[float] | str | None = None, rotate: float | Literal['auto', 'auto-reverse'] | None = None, origin: str | None = None, ease: EaseLike | None = None, begin: Clock | None = None, dur: Clock | None = None, end: Clock | None = None, min: Clock | None = None, max: Clock | None = None, restart: Restart | None = None, repeat_count: RepeatCount | None = None, repeat_dur: Clock | None = None, fill: AnimationFill | None = None, values: Sequence[Any] | str | None = None, from_: Any = None, to: Any = None, by: Any = None, calc_mode: CalcMode | None = None, key_times: Sequence[float] | str | None = None, key_splines: Sequence[tuple[float, float, float, float]] | str | None = None, additive: Additive | None = None, accumulate: Accumulate | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
AnimationElement,_ValueAnimation<animateMotion>: move an element along a path.- Parameters:
*children (MPath) – An optional
mpathnaming the path by reference.path (PathData or PathBuilder or str, optional) – The motion path.
key_points (sequence of float or str, optional) – Progress along the path at each
key_timesentry.rotate (float or {"auto", "auto-reverse"}, optional) – Orientation along the path.
origin (str, optional) – The motion origin.
ease (str, tuple, callable or Ease, optional) – Timing curve along the path (or through
values); seeEase. Along a path it is written withkeyPoints.**kwargs – Timing (see
AnimationElement), values attributes, core and other SVG attributes.
See also
MPathReference a path instead of inlining it.
Examples
>>> str(AnimateMotion(path="M0 0L10 10", dur=2, rotate="auto")) '<animateMotion dur="2s" path="M0 0 L10 10" rotate="auto"/>'
- class AnimateTransform(type: TransformType = TransformType.TRANSLATE, *, begin: Clock | None = None, dur: Clock | None = None, end: Clock | None = None, min: Clock | None = None, max: Clock | None = None, restart: Restart | None = None, repeat_count: RepeatCount | None = None, repeat_dur: Clock | None = None, fill: AnimationFill | None = None, values: Sequence[Any] | str | None = None, from_: Any = None, to: Any = None, by: Any = None, calc_mode: CalcMode | None = None, key_times: Sequence[float] | str | None = None, key_splines: Sequence[tuple[float, float, float, float]] | str | None = None, additive: Additive | None = None, accumulate: Accumulate | None = None, ease: EaseLike | None = None, attribute_name: str | None = None, attribute_type: Literal['CSS', 'XML', 'auto'] | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
SpinShortcut,AnimationElement,_ValueAnimation,_AttributeTarget<animateTransform>: animate thetransformattribute.- Parameters:
type (TransformType, optional) – Kind of transform. Defaults to
TransformType.TRANSLATE.**kwargs – Everything
Animatetakes;attribute_namedefaults to"transform".
See also
AnimateAnimate any other attribute.
Examples
>>> AnimateTransform(TransformType.SCALE, from_=1, to=2, dur=1).get("type") <TransformType.SCALE: 'scale'>
- class AnimationElement(*args: Element | str, begin: str | float | None = None, dur: str | float | None = None, end: str | float | None = None, min: str | float | None = None, max: str | float | None = None, restart: Restart = Restart.ALWAYS, repeat_count: float | Literal['indefinite'] | None = None, repeat_dur: str | float | None = None, fill: AnimationFill | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,ConditionalAttributes,ExternalResourcesAttribute,CoreAttributesTiming attributes shared by every animation element.
Numeric clock values are written in seconds;
float("inf")forrepeat_countis written asindefinite.- Parameters:
*args (Element) – Child elements.
begin (float or str, optional) – Clock values: seconds as a number or any SMIL timing string.
dur (float or str, optional) – Clock values: seconds as a number or any SMIL timing string.
end (float or str, optional) – Clock values: seconds as a number or any SMIL timing string.
min (float or str, optional) – Clock values: seconds as a number or any SMIL timing string.
max (float or str, optional) – Clock values: seconds as a number or any SMIL timing string.
restart (Restart, optional) – When the animation may restart. Defaults to
Restart.ALWAYS, which is not written.repeat_count (float or "indefinite", optional) – Number of repeats.
repeat_dur (float or str, optional) – Total duration of the repeats.
fill (AnimationFill, optional) – State after the animation ends.
**kwargs – Presentation, core and other SVG attributes in Python spelling.
Examples
>>> str(Set("fill", "red", begin=1, dur=2)) '<set attributeName="fill" begin="1s" dur="2s" to="red"/>'
- class AnimationFill(*values)[source]¶
Bases:
KeywordThe animation
fillattribute: the state after the active duration (not paint).See also
AnimationElementTakes
fillas an argument.
Examples
>>> AnimationFill.FREEZE.value 'freeze'
- FREEZE = 'freeze'¶
- REMOVE = 'remove'¶
- class CalcMode(*values)[source]¶
Bases:
KeywordThe
calcModeattribute: how values are interpolated.See also
AnimateTakes
calc_modeas an argument.
Examples
>>> CalcMode.SPLINE.value 'spline'
- DISCRETE = 'discrete'¶
- LINEAR = 'linear'¶
- PACED = 'paced'¶
- SPLINE = 'spline'¶
- class Ease(curve: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] = 'linear')[source]¶
Bases:
objectA timing curve: how an animation’s progress runs over its duration.
Every animation element and every
element.animatepreset takes one asease=, in any of the forms below, and the curve applies to the whole timeline: with severalvaluesthe motion through all of them follows the one curve (keyTimesare moved accordingly). Bézier curves are written as SMILcalcMode="spline"with exactkeySplines; steps ascalcMode="discrete"; a Python function is sampled intovalueswithkeyTimesat 24 to 60 evenly spaced times, more the more the curve bends, and played linearly between them.- Parameters:
curve (str, tuple, callable or Ease, optional) –
One of
a name:
"linear"(the default),"ease","ease-in","ease-out","ease-in-out"(the standard cubic-bézier curves),"step-start"or"step-end";(x1, y1, x2, y2): a cubic bézier from(0, 0)to(1, 1)with0 <= x1, x2 <= 1;ybeyond0..1overshoots (and is then sampled, since SMIL splines stay inside the unit square);("steps", n)or("steps", n, "start"): n equal jumps, at the end (default) or the start of each interval;a function from time
0..1to progress, normally0..1but free to overshoot (f(0)should be 0 andf(1)1);another
Ease.
- Raises:
ValueError – For an unknown name, a bézier
xoutside0..1or a step count below 1.TypeError – For anything else.
See also
AnimateTakes
ease.
Examples
>>> import svgwriter as svg >>> svg.Ease("ease-in")(0.5) < 0.5 True >>> slide = svg.Animate(attribute_name="x", from_=0, to=100, dur=1, ease="ease-out") >>> slide.get("keySplines"), slide.get("calcMode") ('0 0 0.58 1', 'spline') >>> svg.Ease(("steps", 4))(0.6) 0.5 >>> svg.Ease(lambda t: t * t)(0.5) 0.25
Notes
Progress at time
xalong a bézier is found by solvingx(s) = xfor the curve parameter with Newton’s method, falling back to bisection, the same way the SMIL evaluator behinddoc.atplayskeySplines.- time_of(progress: float) float[source]¶
The earliest time (
0..1) at which the curve reaches progress.- Parameters:
progress (float) – Target progress.
- Returns:
float – The time, or 1.0 when the curve never gets there.
Examples
>>> round(Ease("ease-in").time_of(0.5), 3) 0.657
- smil(values: Sequence[str], key_times: Sequence[float] | None = None, *, discrete: bool = False) dict[str, Any][source]¶
SMIL timing attributes that play values along this curve over the whole timeline.
- Parameters:
- Returns:
dict – Some of
values,key_times,key_splinesandcalc_mode, in Python spelling; empty for a linear curve.
Examples
>>> Ease("ease-in").smil(["0", "10", "20"])["key_times"] [0.0, 0.6575, 1.0]
- class MPath(href: str | Element | None = None, *, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
XLinkAttributes,ExternalResourcesAttribute,CoreAttributes<mpath>: the motion path ofanimateMotionby reference.- Parameters:
See also
AnimateMotionThe element that contains it.
Examples
>>> import svgwriter as svg >>> p = svg.Path("M0 0L10 10", id="track") >>> 'href="#track"' in str(MPath(p)) True
- class Restart(*values)[source]¶
Bases:
KeywordThe
restartattribute: when an animation may begin again.See also
AnimationElementTakes
restartas an argument.
Examples
>>> Restart.NEVER.value 'never'
- ALWAYS = 'always'¶
- WHEN_NOT_ACTIVE = 'whenNotActive'¶
- NEVER = 'never'¶
- class Set(attribute_name: str | None = None, to: Any = None, *, begin: Clock | None = None, dur: Clock | None = None, end: Clock | None = None, min: Clock | None = None, max: Clock | None = None, restart: Restart | None = None, repeat_count: RepeatCount | None = None, repeat_dur: Clock | None = None, fill: AnimationFill | None = None, attribute_type: Literal['CSS', 'XML', 'auto'] | None = None, href: str | Element | None = None, xlink_title: str | None = None, xlink_show: str | None = None, xlink_actuate: str | None = None, xlink_role: str | None = None, xlink_arcrole: str | None = None, required_features: str | Sequence[str] | None = None, required_extensions: str | Sequence[str] | None = None, system_language: str | Sequence[str] | None = None, external_resources_required: bool | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any)[source]¶
Bases:
AnimationElement,_AttributeTarget<set>: assign a value for a duration.- Parameters:
attribute_name (str, optional) – The attribute to set.
to (object, optional) – The value to assign.
**kwargs – Timing (see
AnimationElement), core and other SVG attributes.
See also
AnimateInterpolate instead of assigning.
Examples
>>> str(Set("visibility", "hidden", begin=2)) '<set attributeName="visibility" begin="2s" to="hidden"/>'
Animation presets¶
element.animate returns a Motion; its methods add SMIL children and chain. @svg.preset.animation
adds presets of your own as more methods, and Motion.apply runs any animation function with typed
options (see Preset functions).
- class Motion(element: Element)[source]¶
Bases:
TransformPresetsAnimation presets for one element; every method adds SMIL children and returns
selfto chain.Reach it as
element.animate. The SMIL plays in browsers, andsvgwriter.Document.at(), video export and animated GIF/APNG/WebP play it too. Each preset takesdur(seconds),begin(seconds),repeat(a count, or"indefinite"),freeze(keep the end state; default True) andease, a timing curve over the whole preset (a name such as"ease-in-out", a bézier 4-tuple,("steps", n)or a function; seeEase).showandhideact at one instant, so they take only the moment. Presets added with@svg.preset.animationare methods too, and so are behaviors (@svg.preset.behavior), which attach to the scene owning the element.- Parameters:
element (Element) – What to animate.
Examples
>>> import svgwriter as svg >>> dot = svg.circle(10, 10, 5, fill="red") >>> _ = dot.animate.fade_in(0.5).spin(2, begin=0.5) >>> [child.tag for child in dot.children] ['animate', 'animateTransform'] >>> _ = dot.animate.move_to(80, 10, ease="ease-in-out") >>> dot.children[-1].get("keySplines") '0.42 0 0.58 1'
- element¶
- on(event: str, source: Element | None = None) Triggered[source]¶
The presets started by a pointer event instead of the clock:
el.animate.on("click").pulse().Each preset’s
beginbecomes a delay after the event. SVG in browsers and viewers plays the animation when the event happens, and can replay it; still images, PDF and video show the resting state.- Parameters:
- Returns:
Triggered – The presets, each returning the same object to chain.
- Raises:
ValueError – If event is not a known event name.
Examples
>>> import svgwriter as svg >>> doc = svg.Document(width=80, height=30) >>> button = doc.rect(0, 0, 30, 20, id="go") >>> ball = doc.circle(50, 10, 5) >>> _ = ball.animate.on("click", button).move_to(70, 10, begin=0.2) >>> str(ball.children[-1].get("begin")) 'go.click+0.2s'
- apply(function: ~collections.abc.Callable[[~typing.Concatenate[~svgwriter.model.elements._motion.Motion, ~P]], ~svgwriter.model.elements._motion.Motion | None], *args: ~typing.~P, **kwargs: ~typing.~P) Motion[source]¶
Run an animation function on this element:
function(self, *args, **kwargs).Typed with the function’s own parameters, so editors complete and check its options. The function need not be registered;
@svg.preset.animationalso makes itelement.animate.<name>.- Parameters:
function (callable) –
function(motion, *, option=default, ...)returning the motion or None.*args – Passed on to function.
**kwargs – Passed on to function.
- Returns:
Motion – This motion, to chain further presets.
Examples
>>> import svgwriter as svg >>> def lift(motion: svg.Motion, *, height: float = 8) -> svg.Motion: ... return motion.move_by(0, -height) >>> dot = svg.circle(0, 0, 2) >>> dot.animate.apply(lift, height=3).fade_in().element is dot True
- tween(attribute: str, start: Any, end: Any, dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Change any attribute from start to end (numbers, lengths, colors, lists).
- fade_in(dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Opacity from 0 to 1.
- fade_out(dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Opacity from 1 to 0.
- draw(dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Draw the stroke on from its start, as if by a pen (dash offset from full length to 0).
- create(dur: float = 1.0, *, begin: float = 0.0, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Draw the outline on, then fade the fill in; a group creates every child at once.
A shape without a stroke is drawn with its fill color. Every contour starts drawing together, at the same pen speed. ease shapes the drawing and the fade each.
- uncreate(dur: float = 1.0, *, begin: float = 0.0, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
The reverse of
create(): fade the fill out, then draw the outline off.
- write(dur: float = 1.0, *, begin: float = 0.0, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Create a
<text>character by character (a group child by child), each starting before the last ends.ease spaces the starts along the curve and shapes each character’s drawing.
- wipe(side: str = 'left', dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Reveal the element from one side (
left,right,top,bottom) with a growing clip.
- typewriter(dur: float = 1.0, *, begin: float = 0.0, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Show a
<text>one character at a time over dur seconds (ease spaces the characters).
- follow(path: Any, dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, rotate: bool = True, freeze: bool = True, ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Travel along path (an element or path data), turning with it when rotate.
- blink(dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = 'indefinite', ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Switch fully off and on again, by default forever.
- color_cycle(colors: list[Any], dur: float = 1.0, *, attribute: str = 'fill', begin: float = 0.0, repeat: float | str | None = 'indefinite', ease: Ease | str | tuple[float, float, float, float] | tuple[Any, ...] | Callable[[float], float] | None = None) Motion[source]¶
Blend through colors (and back to the first), by default forever.
- morph(target: Element, dur: float = 1.0, *, begin: float = 0.0, repeat: float | str | None = None, freeze: bool = True, ease: EaseLike | None = None) Motion[source]¶
Turn this
<path>’s outline into target’s, matching their segments first.Both outlines are brought to the same commands and segment count, so the
dattribute can be interpolated; the path’s owndis rewritten to the matched start shape, which looks the same.- Parameters:
target (Element) – Any shape with an outline (
<rect>,<circle>,<path>…).dur (float, optional) – Seconds the morph takes. Defaults to 1.0.
begin (float, optional) – Seconds before it starts. Defaults to 0.0.
repeat (float or str, optional) –
repeatCount: a number or"indefinite". Defaults to None (once).freeze (bool, optional) – Keep the target shape after the end. Defaults to True.
ease (str or callable, optional) – Easing name or curve. Defaults to None (linear).
- Returns:
Motion – This object, for chaining.
- Raises:
TypeError – If the element is not a
<path>; convert it withto_path()first.
See also
svgwriter.interpolateThe segment matching and blending used here.
Examples
>>> import svgwriter as svg >>> shape = svg.rect(0, 0, 20, 20).to_path() >>> _ = shape.animate.morph(svg.circle(10, 10, 10), 2) >>> anim = shape.find(svg.Animate) >>> anim.get("attributeName"), anim.get("dur") ('d', '2s') >>> svg.circle(0, 0, 1).animate.morph(shape) Traceback (most recent call last): ... TypeError: morph animates a <path>'s d; convert first with element.to_path()