movis.layer.drawing.Text#

class movis.layer.drawing.Text(text: str | Callable[[float], str], font_size: float, font_family: str = 'Sans Serif', font_style: str | None = None, color: tuple[int, int, int] | str | None = None, contents: Sequence[FillProperty | StrokeProperty] = (), line_spacing: int | None = None, text_alignment: TextAlignment | str = TextAlignment.CENTER, duration: float = 1000000.0)[source]#

Draw a text.

Args:
text:

the text to be drawn. It can be a string or a callable object. If it is a callable object, it must accept a float value representing the time, and return a string.

font_size:

the font size of the text.

font_family:

the font family of the text. It must be one of the available fonts (e.g., "Helvetica"). To see the list of available fonts, run movis.layer.Text.available_fonts().

font_style:

the font style of the text. It must be one of the available styles of the given font family (e.g., "Bold"). To see the list of available styles, un movis.layer.Text.available_styles(font_name).

color:

the color of the text with a tuple of (r, g, b), or a string representing a color name (e.g., "#ff0000" or "red"). If None, this layer uses the contents argument to draw the text.

contents:

A sequence of FillProperty or StrokeProperty objects, which will be drawn on top of the text. If an empty sequence is given, the text will be filled with the color argument.

line_spacing:

the line spacing of the text. If None, the line spacing is automatically determined.

text_alignment:

the text alignment. If string is given, it must be one of "left", "center", or "right". It also accepts a TextAlignment enum.

duration:

the duration for which the text should be displayed.

Animateable Attributes:

font_size

Methods

static available_fonts() Sequence[str][source]#

Returns the list of available fonts.

static available_styles(font_name: str) Sequence[str][source]#

Returns the list of available styles of the given font family.

classmethod from_timeline(start_times: Sequence[float], end_times: Sequence[float], texts: Sequence[str], **kwargs) Text[source]#

Create a text layer from a timeline.

This method is useful when you want to display different texts at different times (e.g., displaying a subtitle). Note that other arguments are the same as the constructor.

Args:
start_times:

A sequence of start times of the texts.

end_times:

A sequence of end times of the texts.

texts:

A sequence of texts to be displayed.

Returns:

A new Text object.

get_key(time: float) tuple[str, Hashable][source]#

Returns the state of the layer at the given time.

get_size(time: float = 0.0) tuple[int, int][source]#

Returns the size of the text at the given time.

Note

The returned size is the size of the text drawn on the canvas, and it may be different from the size of the text itself.

Args:
time:

The time at which the size of the text is measured.

get_text(time: float = 0.0) str[source]#

Returns the text to be drawn at the given time.

Attributes

attributes

A dictionary of attributes that are used to generate cache keys.

contents

duration

font_family

font_style

line_spacing

text

text_alignment