Drawing
momapy.drawing
SVG-like drawing elements for momapy.
This module provides classes for creating and manipulating SVG-like drawing elements including paths, shapes, text, filters, and groups. It supports transformations, styling attributes, and conversion to geometry primitives.
Examples:
from momapy.drawing import Path, MoveTo, LineTo, Rectangle, Text
from momapy.geometry import Point
from momapy.coloring import red, blue
# Create a simple path
path = Path(
actions=(
MoveTo(Point(0, 0)),
LineTo(Point(10, 10)),
),
stroke=red,
stroke_width=2.0
)
# Create a rectangle
rect = Rectangle(
point=Point(5, 5),
width=10,
height=10,
fill=blue,
stroke=red
)
# Create text
text = Text(
text="Hello",
point=Point(10, 10),
font_size=14.0
)
Classes:
| Name | Description |
|---|---|
ClosePath |
Close the current path. |
CompositeEffect |
Composite filter effect. |
CompositionOperator |
Composition operators for filter effects. |
CurveTo |
Draw a cubic Bezier curve. |
DrawingElement |
Abstract base class for drawing elements. |
DropShadowEffect |
Drop shadow filter effect. |
EdgeMode |
Edge mode for blur effects. |
Ellipse |
Ellipse drawing element. |
EllipticalArc |
Draw an elliptical arc. |
FillRule |
Fill rule for complex shapes. |
Filter |
Filter with multiple effects. |
FilterEffect |
Abstract base class for filter effects. |
FilterEffectInput |
Filter effect input types. |
FilterUnits |
Units for filter regions. |
FloodEffect |
Flood filter effect. |
FontStyle |
Font style options. |
FontWeight |
Font weight options. |
GaussianBlurEffect |
Gaussian blur filter effect. |
Group |
Group of drawing elements. |
LineTo |
Draw a line to a point. |
MoveTo |
Move to a point (start a new subpath). |
NoneValueType |
Singleton type for None values (as in SVG). |
OffsetEffect |
Offset filter effect. |
Path |
Path drawing element composed of path actions. |
PathAction |
Abstract base class for path actions. |
QuadraticCurveTo |
Draw a quadratic Bezier curve. |
Rectangle |
Rectangle drawing element with optional rounded corners. |
Text |
Text drawing element. |
TextAnchor |
Text anchor options. |
Functions:
| Name | Description |
|---|---|
drawing_elements_to_geometry |
Convert drawing elements to geometry primitives. |
get_drawing_elements_anchor_point |
Get anchor point of drawing elements. |
get_drawing_elements_angle |
Get border point at an angle from center. |
get_drawing_elements_bbox |
Get bounding box of drawing elements. |
get_drawing_elements_border |
Get border point in a direction from center. |
get_initial_value |
Get the initial value of a presentation attribute. |
Attributes:
| Name | Type | Description |
|---|---|---|
NoneValue |
A singleton value for type |
ClosePath
dataclass
Bases: PathAction
Close the current path.
Methods:
| Name | Description |
|---|---|
transformed |
Apply a transformation. |
transformed
transformed(transformation: Transformation, current_point: Point) -> ClosePath
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation (unused). |
required |
current_point
|
Point
|
Current point (unused). |
required |
Returns:
| Type | Description |
|---|---|
ClosePath
|
A new ClosePath. |
Source code in src/momapy/drawing.py
CompositeEffect
dataclass
CompositeEffect(result: str | None = None, *, in_: FilterEffectInput | str | None = None, in2: FilterEffectInput | str | None = None, operator: CompositionOperator | None = OVER, k1: float = 0.0, k2: float = 0.0, k3: float = 0.0, k4: float = 0.0)
Bases: FilterEffect
Composite filter effect.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
str | None
|
The name of the result |
None
|
in_
|
FilterEffectInput | str | None
|
The first effect input or the name of the first filter effect input |
None
|
in2
|
FilterEffectInput | str | None
|
The second effect input or the name of the second filter effect input |
None
|
operator
|
CompositionOperator | None
|
The operator to be used to compute the composite effect |
<CompositionOperator.OVER: 0>
|
k1
|
float
|
k1 coefficient for the arithmetic operator |
0.0
|
k2
|
float
|
k2 coefficient for the arithmetic operator |
0.0
|
k3
|
float
|
k3 coefficient for the arithmetic operator |
0.0
|
k4
|
float
|
k4 coefficient for the arithmetic operator |
0.0
|
CompositionOperator
Bases: Enum
Composition operators for filter effects.
CurveTo
dataclass
Bases: PathAction
Draw a cubic Bezier curve.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point of the curve to action |
required |
control_point1
|
Point
|
The first control point of the curve to action |
required |
control_point2
|
Point
|
The second control point of the curve to action |
required |
Methods:
| Name | Description |
|---|---|
to_geometry |
Convert to CubicBezierCurve geometry. |
transformed |
Apply a transformation. |
to_geometry
to_geometry(current_point: Point) -> CubicBezierCurve
Convert to CubicBezierCurve geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
CubicBezierCurve
|
A CubicBezierCurve. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point) -> CurveTo
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Start point (unused). |
required |
Returns:
| Type | Description |
|---|---|
CurveTo
|
A new CurveTo with transformed points. |
Source code in src/momapy/drawing.py
DrawingElement
dataclass
DrawingElement(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None)
Bases: ABC
Abstract base class for drawing elements.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_
|
str | None
|
The class name of the drawing element |
None
|
fill
|
NoneValueType | Color | None
|
The fill color of the drawing element |
None
|
fill_rule
|
FillRule | None
|
The fill rule of the drawing element |
None
|
filter
|
NoneValueType | Filter | None
|
The filter of the drawing element |
None
|
font_family
|
str | None
|
The font family of the drawing element |
None
|
font_size
|
float | None
|
The font size of the drawing element |
None
|
font_style
|
FontStyle | None
|
The font style of the drawing element |
None
|
font_weight
|
FontWeight | int | None
|
The font weight of the drawing element |
None
|
id_
|
str | None
|
The id of the drawing element |
None
|
stroke
|
NoneValueType | Color | None
|
The stroke color of the drawing element |
None
|
stroke_dasharray
|
NoneValueType | tuple[float, ...] | None
|
The stroke dasharray of the drawing element |
None
|
stroke_dashoffset
|
NoneValueType | float | None
|
The stroke dashoffset of the drawing element |
None
|
stroke_width
|
NoneValueType | float | None
|
The stroke width of the drawing element |
None
|
text_anchor
|
TextAnchor | None
|
The text anchor of the drawing element |
None
|
transform
|
NoneValueType | tuple[Transformation] | None
|
The transform of the drawing element |
None
|
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_geometry |
Convert to a list of geometry primitives. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_geometry
abstractmethod
to_geometry() -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert to a list of geometry primitives.
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
A list of geometry primitives. |
Source code in src/momapy/drawing.py
DropShadowEffect
dataclass
DropShadowEffect(result: str | None = None, *, dx: float = 0.0, dy: float = 0.0, std_deviation: float = 0.0, flood_opacity: float = 1.0, flood_color: Color = black)
Bases: FilterEffect
Drop shadow filter effect.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
str | None
|
The name of the result |
None
|
dx
|
float
|
The horizontal offset of the shadow |
0.0
|
dy
|
float
|
The vertical offset of the shadow |
0.0
|
std_deviation
|
float
|
The standard deviation to be used to compute the shadow |
0.0
|
flood_opacity
|
float
|
The flood opacity of the shadow |
1.0
|
flood_color
|
Color
|
The color of the shadow |
Color(red=0, green=0, blue=0, alpha=1.0)
|
Methods:
| Name | Description |
|---|---|
to_compat |
Convert to more compatible filter effects. |
to_compat
to_compat() -> list[FilterEffect]
Convert to more compatible filter effects.
Returns:
| Type | Description |
|---|---|
list[FilterEffect]
|
List of equivalent filter effects. |
Source code in src/momapy/drawing.py
EdgeMode
Bases: Enum
Edge mode for blur effects.
Ellipse
dataclass
Ellipse(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, point: Point, rx: float, ry: float)
Bases: DrawingElement
Ellipse drawing element.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_
|
str | None
|
The class name of the drawing element |
None
|
fill
|
NoneValueType | Color | None
|
The fill color of the drawing element |
None
|
fill_rule
|
FillRule | None
|
The fill rule of the drawing element |
None
|
filter
|
NoneValueType | Filter | None
|
The filter of the drawing element |
None
|
font_family
|
str | None
|
The font family of the drawing element |
None
|
font_size
|
float | None
|
The font size of the drawing element |
None
|
font_style
|
FontStyle | None
|
The font style of the drawing element |
None
|
font_weight
|
FontWeight | int | None
|
The font weight of the drawing element |
None
|
id_
|
str | None
|
The id of the drawing element |
None
|
stroke
|
NoneValueType | Color | None
|
The stroke color of the drawing element |
None
|
stroke_dasharray
|
NoneValueType | tuple[float, ...] | None
|
The stroke dasharray of the drawing element |
None
|
stroke_dashoffset
|
NoneValueType | float | None
|
The stroke dashoffset of the drawing element |
None
|
stroke_width
|
NoneValueType | float | None
|
The stroke width of the drawing element |
None
|
text_anchor
|
TextAnchor | None
|
The text anchor of the drawing element |
None
|
transform
|
NoneValueType | tuple[Transformation] | None
|
The transform of the drawing element |
None
|
point
|
Point
|
The point of the ellipse |
required |
rx
|
float
|
The x-radius of the ellipse |
required |
ry
|
float
|
The y-radius of the ellipse |
required |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_geometry |
Convert to a list of geometry primitives. |
to_path |
Convert to a Path. |
transformed |
Apply a transformation. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry() -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert to a list of geometry primitives.
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
A list of geometry primitives. |
Source code in src/momapy/drawing.py
to_path
to_path() -> Path
Convert to a Path.
Returns:
| Type | Description |
|---|---|
Path
|
A Path approximating the ellipse. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Path
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
A transformed Path. |
Source code in src/momapy/drawing.py
EllipticalArc
dataclass
EllipticalArc(point: Point, rx: float, ry: float, x_axis_rotation: float, arc_flag: int, sweep_flag: int)
Bases: PathAction
Draw an elliptical arc.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point of the elliptical arc action |
required |
rx
|
float
|
The x-radius of the elliptical arc action |
required |
ry
|
float
|
The y-radius of the elliptical arc action |
required |
x_axis_rotation
|
float
|
The x axis rotation of the elliptical arc action |
required |
arc_flag
|
int
|
The arc flag of the elliptical arc action |
required |
sweep_flag
|
int
|
The sweep flag of the elliptical arc action |
required |
Methods:
| Name | Description |
|---|---|
to_geometry |
Convert to geometry. |
transformed |
Apply a transformation. |
to_geometry
to_geometry(current_point: Point) -> EllipticalArc
Convert to geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
An EllipticalArc geometry. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point) -> EllipticalArc
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
EllipticalArc
|
A new EllipticalArc with transformed parameters. |
Source code in src/momapy/drawing.py
FillRule
Bases: Enum
Fill rule for complex shapes.
Filter
dataclass
Filter(*, id_: str = make_uuid4_as_str(), filter_units: FilterUnits = OBJECT_BOUNDING_BOX, effects: tuple[FilterEffect] = tuple(), width: float | str = '120%', height: float | str = '120%', x: float | str = '-10%', y: float | str = '-10%')
Bases: object
Filter with multiple effects.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
str
|
'24661978-e076-423c-af14-fe162c4fe3d3'
|
|
filter_units
|
FilterUnits
|
|
<FilterUnits.OBJECT_BOUNDING_BOX: 1>
|
effects
|
tuple[FilterEffect]
|
Built-in immutable sequence. If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items. If the argument is a tuple, the return value is the same object. |
<dynamic>
|
width
|
float | str
|
|
'120%'
|
height
|
float | str
|
|
'120%'
|
x
|
float | str
|
|
'-10%'
|
y
|
float | str
|
|
'-10%'
|
Methods:
| Name | Description |
|---|---|
to_compat |
Convert to compatible filter with simpler effects. |
to_compat
Convert to compatible filter with simpler effects.
Returns:
| Type | Description |
|---|---|
Self
|
A filter with effects replaced by simpler equivalents. |
Source code in src/momapy/drawing.py
FilterEffect
dataclass
Bases: ABC
Abstract base class for filter effects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
str | None
|
The name of the result |
None
|
FilterEffectInput
Bases: Enum
Filter effect input types.
FilterUnits
Bases: Enum
Units for filter regions.
FloodEffect
dataclass
Bases: FilterEffect
Flood filter effect.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
str | None
|
The name of the result |
None
|
flood_color
|
Color
|
The color of the flood effect |
Color(red=0, green=0, blue=0, alpha=1.0)
|
flood_opacity
|
float
|
The opacity of the flood effect |
1.0
|
FontStyle
Bases: Enum
Font style options.
FontWeight
Bases: Enum
Font weight options.
GaussianBlurEffect
dataclass
GaussianBlurEffect(result: str | None = None, *, in_: FilterEffectInput | str | None = None, std_deviation: float = 0.0, edge_mode: NoneValueType | EdgeMode = NoneValue)
Bases: FilterEffect
Gaussian blur filter effect.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
str | None
|
The name of the result |
None
|
in_
|
FilterEffectInput | str | None
|
|
None
|
std_deviation
|
float
|
|
0.0
|
edge_mode
|
NoneValueType | EdgeMode
|
|
<momapy.drawing.NoneValueType object at 0x7fbe12e88d70>
|
Group
dataclass
Group(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, elements: tuple[DrawingElement] = tuple())
Bases: DrawingElement
Group of drawing elements.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_
|
str | None
|
The class name of the drawing element |
None
|
fill
|
NoneValueType | Color | None
|
The fill color of the drawing element |
None
|
fill_rule
|
FillRule | None
|
The fill rule of the drawing element |
None
|
filter
|
NoneValueType | Filter | None
|
The filter of the drawing element |
None
|
font_family
|
str | None
|
The font family of the drawing element |
None
|
font_size
|
float | None
|
The font size of the drawing element |
None
|
font_style
|
FontStyle | None
|
The font style of the drawing element |
None
|
font_weight
|
FontWeight | int | None
|
The font weight of the drawing element |
None
|
id_
|
str | None
|
The id of the drawing element |
None
|
stroke
|
NoneValueType | Color | None
|
The stroke color of the drawing element |
None
|
stroke_dasharray
|
NoneValueType | tuple[float, ...] | None
|
The stroke dasharray of the drawing element |
None
|
stroke_dashoffset
|
NoneValueType | float | None
|
The stroke dashoffset of the drawing element |
None
|
stroke_width
|
NoneValueType | float | None
|
The stroke width of the drawing element |
None
|
text_anchor
|
TextAnchor | None
|
The text anchor of the drawing element |
None
|
transform
|
NoneValueType | tuple[Transformation] | None
|
The transform of the drawing element |
None
|
elements
|
tuple[DrawingElement]
|
The elements of the group element |
<dynamic>
|
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_geometry |
Convert to a list of geometry primitives. |
transformed |
Apply a transformation to all elements. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry() -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert to a list of geometry primitives.
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
A list of geometry primitives from all child elements. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Self
Apply a transformation to all elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new Group with transformed elements. |
Source code in src/momapy/drawing.py
LineTo
dataclass
LineTo(point: Point)
Bases: PathAction
Draw a line to a point.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point of the line to action |
required |
Methods:
| Name | Description |
|---|---|
to_geometry |
Convert to a segment. |
transformed |
Apply a transformation. |
to_geometry
transformed
transformed(transformation: Transformation, current_point: Point) -> Self
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Current point (unused). |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new LineTo with transformed point. |
Source code in src/momapy/drawing.py
MoveTo
dataclass
MoveTo(point: Point)
Bases: PathAction
Move to a point (start a new subpath).
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point of the move to action |
required |
Methods:
| Name | Description |
|---|---|
transformed |
Apply a transformation. |
transformed
transformed(transformation: Transformation, current_point: Point) -> MoveTo
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Current point (unused). |
required |
Returns:
| Type | Description |
|---|---|
MoveTo
|
A new MoveTo with transformed point. |
Source code in src/momapy/drawing.py
NoneValueType
Bases: object
Singleton type for None values (as in SVG).
OffsetEffect
dataclass
OffsetEffect(result: str | None = None, *, in_: FilterEffectInput | str | None = None, dx: float = 0.0, dy: float = 0.0)
Bases: FilterEffect
Offset filter effect.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
str | None
|
The name of the result |
None
|
in_
|
FilterEffectInput | str | None
|
|
None
|
dx
|
float
|
|
0.0
|
dy
|
float
|
|
0.0
|
Path
dataclass
Path(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, actions: tuple[PathAction] = tuple())
Bases: DrawingElement
Path drawing element composed of path actions.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_
|
str | None
|
The class name of the drawing element |
None
|
fill
|
NoneValueType | Color | None
|
The fill color of the drawing element |
None
|
fill_rule
|
FillRule | None
|
The fill rule of the drawing element |
None
|
filter
|
NoneValueType | Filter | None
|
The filter of the drawing element |
None
|
font_family
|
str | None
|
The font family of the drawing element |
None
|
font_size
|
float | None
|
The font size of the drawing element |
None
|
font_style
|
FontStyle | None
|
The font style of the drawing element |
None
|
font_weight
|
FontWeight | int | None
|
The font weight of the drawing element |
None
|
id_
|
str | None
|
The id of the drawing element |
None
|
stroke
|
NoneValueType | Color | None
|
The stroke color of the drawing element |
None
|
stroke_dasharray
|
NoneValueType | tuple[float, ...] | None
|
The stroke dasharray of the drawing element |
None
|
stroke_dashoffset
|
NoneValueType | float | None
|
The stroke dashoffset of the drawing element |
None
|
stroke_width
|
NoneValueType | float | None
|
The stroke width of the drawing element |
None
|
text_anchor
|
TextAnchor | None
|
The text anchor of the drawing element |
None
|
transform
|
NoneValueType | tuple[Transformation] | None
|
The transform of the drawing element |
None
|
actions
|
tuple[PathAction]
|
The actions of the path |
<dynamic>
|
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_geometry |
Convert to a list of geometry primitives. |
transformed |
Apply a transformation to all actions. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry() -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert to a list of geometry primitives.
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
A list of Segment, QuadraticBezierCurve, CubicBezierCurve, |
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
or EllipticalArc objects. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Self
Apply a transformation to all actions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new Path with transformed actions. |
Source code in src/momapy/drawing.py
QuadraticCurveTo
dataclass
Bases: PathAction
Draw a quadratic Bezier curve.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point
|
The point of the quadratic curve to action |
required |
control_point
|
Point
|
The control point of the quadratic curve to action |
required |
Methods:
| Name | Description |
|---|---|
to_curve_to |
Convert to cubic CurveTo. |
to_geometry |
Convert to QuadraticBezierCurve geometry. |
transformed |
Apply a transformation. |
to_curve_to
Convert to cubic CurveTo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
CurveTo
|
An equivalent CurveTo. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry(current_point: Point) -> QuadraticBezierCurve
Convert to QuadraticBezierCurve geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_point
|
Point
|
Start point. |
required |
Returns:
| Type | Description |
|---|---|
QuadraticBezierCurve
|
A QuadraticBezierCurve. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation, current_point: Point) -> QuadraticCurveTo
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
current_point
|
Point
|
Start point (unused). |
required |
Returns:
| Type | Description |
|---|---|
QuadraticCurveTo
|
A new QuadraticCurveTo with transformed points. |
Source code in src/momapy/drawing.py
Rectangle
dataclass
Rectangle(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, point: Point, width: float, height: float, rx: float, ry: float)
Bases: DrawingElement
Rectangle drawing element with optional rounded corners.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_
|
str | None
|
The class name of the drawing element |
None
|
fill
|
NoneValueType | Color | None
|
The fill color of the drawing element |
None
|
fill_rule
|
FillRule | None
|
The fill rule of the drawing element |
None
|
filter
|
NoneValueType | Filter | None
|
The filter of the drawing element |
None
|
font_family
|
str | None
|
The font family of the drawing element |
None
|
font_size
|
float | None
|
The font size of the drawing element |
None
|
font_style
|
FontStyle | None
|
The font style of the drawing element |
None
|
font_weight
|
FontWeight | int | None
|
The font weight of the drawing element |
None
|
id_
|
str | None
|
The id of the drawing element |
None
|
stroke
|
NoneValueType | Color | None
|
The stroke color of the drawing element |
None
|
stroke_dasharray
|
NoneValueType | tuple[float, ...] | None
|
The stroke dasharray of the drawing element |
None
|
stroke_dashoffset
|
NoneValueType | float | None
|
The stroke dashoffset of the drawing element |
None
|
stroke_width
|
NoneValueType | float | None
|
The stroke width of the drawing element |
None
|
text_anchor
|
TextAnchor | None
|
The text anchor of the drawing element |
None
|
transform
|
NoneValueType | tuple[Transformation] | None
|
The transform of the drawing element |
None
|
point
|
Point
|
The point of the rectangle |
required |
width
|
float
|
The width of the rectangle |
required |
height
|
float
|
The height of the rectangle |
required |
rx
|
float
|
The x-radius of the rounded corners of the rectangle |
required |
ry
|
float
|
The y-radius of the rounded corners of the rectangle |
required |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_geometry |
Convert to a list of geometry primitives. |
to_path |
Convert to a Path. |
transformed |
Apply a transformation. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry() -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert to a list of geometry primitives.
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
A list of geometry primitives. |
Source code in src/momapy/drawing.py
to_path
to_path() -> Path
Convert to a Path.
Returns:
| Type | Description |
|---|---|
Path
|
A Path representing the rectangle. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Path
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
A transformed Path. |
Source code in src/momapy/drawing.py
Text
dataclass
Text(*, class_: str | None = None, fill: NoneValueType | Color | None = None, fill_rule: FillRule | None = None, filter: NoneValueType | Filter | None = None, font_family: str | None = None, font_size: float | None = None, font_style: FontStyle | None = None, font_weight: FontWeight | int | None = None, id_: str | None = None, stroke: NoneValueType | Color | None = None, stroke_dasharray: NoneValueType | tuple[float, ...] | None = None, stroke_dashoffset: NoneValueType | float | None = None, stroke_width: NoneValueType | float | None = None, text_anchor: TextAnchor | None = None, transform: NoneValueType | tuple[Transformation] | None = None, text: str, point: Point)
Bases: DrawingElement
Text drawing element.
Attributes:
| Name | Type | Description |
|---|
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_
|
str | None
|
The class name of the drawing element |
None
|
fill
|
NoneValueType | Color | None
|
The fill color of the drawing element |
None
|
fill_rule
|
FillRule | None
|
The fill rule of the drawing element |
None
|
filter
|
NoneValueType | Filter | None
|
The filter of the drawing element |
None
|
font_family
|
str | None
|
The font family of the drawing element |
None
|
font_size
|
float | None
|
The font size of the drawing element |
None
|
font_style
|
FontStyle | None
|
The font style of the drawing element |
None
|
font_weight
|
FontWeight | int | None
|
The font weight of the drawing element |
None
|
id_
|
str | None
|
The id of the drawing element |
None
|
stroke
|
NoneValueType | Color | None
|
The stroke color of the drawing element |
None
|
stroke_dasharray
|
NoneValueType | tuple[float, ...] | None
|
The stroke dasharray of the drawing element |
None
|
stroke_dashoffset
|
NoneValueType | float | None
|
The stroke dashoffset of the drawing element |
None
|
stroke_width
|
NoneValueType | float | None
|
The stroke width of the drawing element |
None
|
text_anchor
|
TextAnchor | None
|
The text anchor of the drawing element |
None
|
transform
|
NoneValueType | tuple[Transformation] | None
|
The transform of the drawing element |
None
|
text
|
str
|
The value of the text element |
required |
point
|
Point
|
The position of the text element |
required |
Methods:
| Name | Description |
|---|---|
bbox |
Get the bounding box. |
get_filter_region |
Get the filter region. |
to_geometry |
Convert to a list of geometry primitives. |
transformed |
Apply a transformation. |
bbox
bbox() -> Bbox
Get the bounding box.
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_filter_region
get_filter_region() -> Bbox
Get the filter region.
Returns:
| Type | Description |
|---|---|
Bbox
|
The filter region bbox. |
Source code in src/momapy/drawing.py
to_geometry
to_geometry() -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert to a list of geometry primitives.
Text has no geometry primitives.
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
An empty list. |
Source code in src/momapy/drawing.py
transformed
transformed(transformation: Transformation) -> Self
Apply a transformation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformation
|
Transformation
|
The transformation. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the text element. |
Source code in src/momapy/drawing.py
TextAnchor
Bases: Enum
Text anchor options.
drawing_elements_to_geometry
drawing_elements_to_geometry(drawing_elements: Sequence[DrawingElement]) -> list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
Convert drawing elements to geometry primitives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Sequence of drawing elements. |
required |
Returns:
| Type | Description |
|---|---|
list[Segment | QuadraticBezierCurve | CubicBezierCurve | EllipticalArc]
|
A list of geometry primitives. |
Source code in src/momapy/drawing.py
get_drawing_elements_anchor_point
get_drawing_elements_anchor_point(drawing_elements: Sequence[DrawingElement], anchor_point: str, center: Point | None = None) -> Point
Get anchor point of drawing elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
anchor_point
|
str
|
Name of anchor point. |
required |
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point
|
The anchor point. |
Source code in src/momapy/drawing.py
get_drawing_elements_angle
get_drawing_elements_angle(drawing_elements: Sequence[DrawingElement], angle: float, unit: str = 'degrees', center: Point | None = None) -> Point | None
Get border point at an angle from center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
angle
|
float
|
The angle. |
required |
unit
|
str
|
Unit ('degrees' or 'radians'). |
'degrees'
|
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point | None
|
The border point or None. |
Source code in src/momapy/drawing.py
get_drawing_elements_bbox
get_drawing_elements_bbox(drawing_elements: Sequence[DrawingElement]) -> Bbox
Get bounding box of drawing elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
Returns:
| Type | Description |
|---|---|
Bbox
|
The bounding box. |
Source code in src/momapy/drawing.py
get_drawing_elements_border
get_drawing_elements_border(drawing_elements: Sequence[DrawingElement], point: Point, center: Point | None = None) -> Point | None
Get border point in a direction from center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drawing_elements
|
Sequence[DrawingElement]
|
Drawing elements. |
required |
point
|
Point
|
Direction point. |
required |
center
|
Point | None
|
Optional center point. |
None
|
Returns:
| Type | Description |
|---|---|
Point | None
|
The border point or None. |
Source code in src/momapy/drawing.py
get_initial_value
Get the initial value of a presentation attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attr_name
|
str
|
Name of the attribute. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The initial value. |