API Reference¶
Rendering¶
- render(text, *, spans=(), font=None, size=12.0, weight=Weight.NORMAL, style=Style.NORMAL, variations=None, width=None, alignment=Alignment.LEFT, line_spacing=None, justify=False, indent=0.0, disable_ligatures=False)¶
Render literal plain text to SVG and structured layout metadata.
textis never interpreted as markup. Userender_markup()for Pango markup, or usespansto style ranges of plain text in the same native layout.- Parameters:
text (str) – Literal Unicode text to render, without embedded NUL characters.
spans (Sequence[TextSpan]) –
TextSpaninstances for half-open code-point ranges oftext. Compatible overlaps compose; conflicting values raiseValueError.font (str | None) – Font family name without embedded NUL characters, or
Nonefor Pango’s default family. To use a font file that is not installed system-wide, register it first withregister_font().size (float) – Positive absolute font size in SVG user-space units.
weight (Weight | int) – Base
Weight/integer andStylefor text not overridden by a span.style (Style) – Base
Weight/integer andStylefor text not overridden by a span.variations (Mapping[str, float] | None) – Mapping of four-printable-ASCII-character OpenType variation-axis tags to finite numeric values. Settings are forwarded to Pango; visible effects depend on the selected font, axis, and renderer backend.
width (float | None) – Positive wrapping width in SVG user-space units, or
Nonefor no width constraint.alignment (Alignment) – Horizontal alignment within
width.line_spacing (float | None) – Positive Pango line-spacing multiplier, or
Nonefor Pango’s default line spacing.justify (bool) – Whether Pango justifies wrapped lines.
indent (float) – Pango indentation in SVG user-space units; negative values create a hanging indentation.
disable_ligatures (bool) – Disable Pango’s standard, discretionary, contextual, historical, and contextual-alternate features (
liga,dlig,clig,hlig, andcalt). This setting takes precedence over conflicting feature declarations inspansor markup.
- Returns:
SVG output plus viewport, bounds, baseline, and per-line metadata.
- Return type:
- Raises:
TypeError, ValueError – If an option or span is invalid.
RenderError – If Pango or Cairo fails while creating the native render result.
- render_markup(markup, *, font=None, size=12.0, weight=Weight.NORMAL, style=Style.NORMAL, variations=None, width=None, alignment=Alignment.LEFT, line_spacing=None, justify=False, indent=0.0, disable_ligatures=False)¶
Render Pango markup to SVG and structured layout metadata.
markupis parsed by Pango; do not pass markup torender(). The layout options have the same meanings as inrender(), except range styling is expressed in markup rather than withTextSpan. Line offsets in the returnedRenderedTextrefer to Pango’s parsed text, not character offsets in the markup source.- Parameters:
- Return type:
Notes
All remaining options have the same contracts as in
render(); markup expresses range styling instead of acceptingTextSpanobjects.- Returns:
SVG output plus viewport, bounds, baseline, and per-line metadata.
- Return type:
- Raises:
MarkupError – If Pango rejects
markup.TypeError, ValueError – If an option is invalid.
RenderError – If Pango or Cairo fails while creating the native render result.
- Parameters:
- validate_markup(markup)¶
Validate a Pango markup string without rendering it.
Returns an empty string when
markupis valid. Otherwise returns a diagnostic explaining why it is invalid.render_markup()turns that diagnostic intoMarkupError. Embedded NUL characters are rejected before Pango parses the source.
Text Models¶
- class TextSpan(start, end, font=None, size=None, weight=None, style=None, foreground=None, features=None, variations=None)¶
Style attributes for a half-open code-point range of plain text.
Pass spans to
manimpango.render(); markup has its own styling syntax and is rendered withmanimpango.render_markup(). Overlap is supported when spans set different attributes. Overlapping spans may not give different values to the same scalar attribute or OpenType tag.- Parameters:
- start, end
Python code-point offsets satisfying
0 <= start <= end <= len(text). The range includesstartand excludesend, matching slicing.
- font¶
Font family name without embedded NUL characters for the range, or
Noneto inherit the render call’s font.- Type:
str | None
- size¶
Positive absolute size in SVG user-space units, or
Noneto inherit the render call’s size.- Type:
float | None
- weight¶
A
Weightmember or integer from 1 through 1000.- Type:
manimpango.enums.Weight | int | None
- style¶
A
Stylemember.- Type:
manimpango.enums.Style | None
- foreground¶
A Pango foreground-color specification without embedded NUL characters, such as
"#3366cc".- Type:
str | None
- features¶
Mapping of four-printable-ASCII-character OpenType feature tags to integer or boolean values. Boolean values are converted to
0or1. Whenmanimpango.render()is called withdisable_ligatures=True, that setting overrides values for its ligature-related tags.- Type:
collections.abc.Mapping[str, int | bool] | None
- variations¶
Mapping of four-printable-ASCII-character OpenType variation-axis tags to finite numeric values. Settings are forwarded to Pango; visible effects depend on the selected font, axis, and renderer backend.
- Type:
collections.abc.Mapping[str, float] | None
- class Bounds(x, y, width, height)¶
A rectangle in the rendered SVG coordinate system.
- x, y
Position of the rectangle’s upper-left corner in SVG user-space units.
- width, height
Non-negative dimensions in the same coordinate system.
- class LineInfo(text, start, end, bounds, baseline)¶
Text and geometry for one rendered line.
For
manimpango.render(),startandendare half-open Python code-point offsets into the input text. Formanimpango.render_markup(), they index Pango’s parsed text rather than the markup source. Pango line separators are excluded from every line range.- start, end
Half-open Python code-point offsets for
textin the appropriate rendered-text source.
- bounds¶
Logical bounds of this line in SVG user-space coordinates.
- Type:
- class RenderedText(svg, width, height, baseline, lines, ink_bounds, logical_bounds)¶
Immutable SVG output and layout metadata from one render operation.
All geometry uses the same SVG user-space coordinate system as
svg. The object is frozen andlinesis always a tuple.- Parameters:
- width, height
Dimensions of the SVG viewport in user-space units.
- lines¶
Per-line text and geometry, in rendering order.
- Type:
- ink_bounds¶
Union of the Pango ink extents: the area touched by glyph drawing.
- Type:
- logical_bounds¶
Union of the Pango logical extents, including layout advances such as whitespace.
- Type:
Font Management¶
- register_font(font_path)¶
Register a font file and return an explicit lifetime handle.
Each call returns a distinct handle. The file path is expanded and resolved strictly before entering the native backend. The font becomes visible to this renderer’s font map immediately and remains available until the final handle for that normalized path is closed.
Use the returned handle as a context manager for temporary registrations. Multiple handles for the same file are reference-counted, so closing one cannot remove a font still used by another.
- Raises:
FontNotFoundError – If the path does not exist.
FontRegistrationError – If the path is not a regular file or the native backend rejects the registration.
- Parameters:
- Return type:
- class FontRegistration(path, *, _token=None)¶
An explicit, reference-counted registration of a font file.
Instances are returned by
register_font(). Closing one handle does not affect other handles for the same normalized path; native unregistration occurs only after the final handle closes. Use the handle as a context manager when the font is needed only for a bounded operation. Unclosed handles intentionally remain active until process exit.Do not instantiate this class directly; obtain it from
register_font().- Parameters:
path (Path)
_token (object | None)
- close()¶
Release this handle’s registration reference, idempotently.
The font remains available while another handle for the same path is open. The final close removes it from subsequent renderer-owned font maps and can raise
FontRegistrationErrorif the native backend cannot complete that transition.- Return type:
None
- list_fonts()¶
Return sorted unique family names visible to the renderer’s font map.
The result includes currently registered custom fonts and is a snapshot; closing a
FontRegistrationcan change later calls.
Enumerations¶
- class Style(value)¶
Font slant style.
- NORMAL¶
The font is upright.
- ITALIC¶
The font uses its italic face when available.
- OBLIQUE¶
The font is slanted from its upright face when available.
- class Weight(value)¶
Font weight (boldness).
This enum inherits from both
intandEnumto allow arbitrary integer values (1-1000) for variable font support. The named members are convenience aliases for standard CSS/OpenType weight values.Examples
Using named weights:
Weight.NORMAL # 400 Weight.BOLD # 700
Using arbitrary integer values (useful for variable fonts):
Weight(450) # 450 550 # directly passed to render()
Exceptions¶
- exception ManimPangoError¶
Base class for ManimPango-specific failures.
- exception RenderError¶
Raised when Pango or Cairo fails during a native render operation.
Invalid public arguments continue to raise
TypeErrororValueError, and invalid markup raisesMarkupError.
- exception MarkupError¶
Raised when Pango markup is malformed.
- exception FontError¶
Base class for font-related failures.
- exception FontNotFoundError¶
Raised when a requested font file does not exist.
- exception FontRegistrationError¶
Raised when a font backend rejects a font registration.
Version Information¶
- get_version_info()¶
Return version strings for ManimPango and its linked libraries.
- __version__¶
The installed ManimPango version string.