Layout

Qualified name: manimpango.Layout

class Layout(text=None, markup=None, font_desc=None, attributes=None, width=None, height=None, alignment=None, justify=None)

A Layout class represents an entire paragraph of text.

Layout provides a high-level driver for formatting entire paragraphs of text at once. This includes paragraph-level functionality such as line breaking, justification, alignment and ellipsization.

A Layout is initialized with a str. The layout can then be rendered. There are a number of parameters to adjust the formatting of a Layout.

When both markup and text is set the behavior is unknown.

Parameters
  • text (str) – The text to be set, by default None.

  • markup (str) – The text encoded in PangoMarkup, by default None.

  • font_desc (FontDescription) – The font description to be used while rendering.

  • attributes (list[TextAttribute]) –

  • width (int) –

  • height (int) –

  • alignment (Alignment) –

  • justify (bool) –

Examples

>>> import manimpango as mp
>>> mp.Layout("hello world")
<Layout text='hello world' markup=None>
Raises

ValueError – If both text and markup is None.

Parameters

Methods

get_bounding_box

Returns the bounding box of the layout.

render

Renders the layout into a PNG or SVG file depending on the filename.

get_bounding_box()

Returns the bounding box of the layout.

Note that it’s heavy to calculate the bounding box of a layout, so it’s better to cache the result.

Example

>>> import manimpango as mp
>>> layout = mp.Layout("hello world")
>>> layout.get_bounding_box()
(0, 0, 82, 19)
Returns

The bounding box of the layout in the form of (x, y, width, height).

Return type

tuple

property height: int

The height to which the text should be ellipsized at.

Raises

TypeError – If height is not a int.

property justify: bool

Whether the text should be justified.

Raises

TypeError – If justify is not a bool.

property markup: str

The markup (in pango markup format) to render.

Raises
render(file_name)

Renders the layout into a PNG or SVG file depending on the filename.

Parameters

file_name (str) – The filename to which the layout should be rendered.

Return type

None

property text: str

The text to render.

Raises

TypeError – If text is not a str.

property width: int

The width to which the text should be wrapped or ellipsized.

Raises

TypeError – If width is not a int.