Canvas Template
A CanvasTemplate defines a transformation recipe for producing a new canvas from
a source canvas and framing decision. Templates specify target dimensions, fit method,
alignment, and rounding strategy. Call apply() to execute the transformation.
fdl.CanvasTemplate(*, id, label='', target_dimensions, target_anamorphic_squeeze=1.0, fit_source=GeometryPath.FRAMING_DIMENSIONS, fit_method=FitMethod.WIDTH, alignment_method_horizontal=HAlign.CENTER, alignment_method_vertical=VAlign.CENTER, round=RoundStrategy(), preserve_from_source_canvas=None, maximum_dimensions=None, pad_to_maximum=False)
Bases: HandleWrapper
CanvasTemplate facade wrapping a C fdl_canvas_template_t handle.
custom_attrs
property
Return all custom attributes as a dictionary.
apply(source_canvas, source_framing, new_canvas_id, new_fd_name, source_context_label=None, context_creator=None)
Apply this canvas template to a source canvas/framing decision.
custom_attrs_count()
Return the number of custom attributes on this object.
from_model(model)
classmethod
Create a standalone CanvasTemplate facade from a Pydantic model.
Note: Creates a temporary backing document. The returned object is self-contained but not attached to any parent FDL document.
get_custom_attr(name)
Get a custom attribute value by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Attribute name (without |
required |
Returns:
| Type | Description |
|---|---|
str | int | float | bool | PointFloat | DimensionsFloat | DimensionsInt | None
|
The attribute value, or None if not found. |
has_custom_attr(name)
Check if a custom attribute exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Attribute name (without |
required |
remove_custom_attr(name)
Remove a custom attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Attribute name (without |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the attribute was removed, False if it was not found. |
set_custom_attr(name, value)
Set a custom attribute. Type is inferred from value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Attribute name (without |
required |
value
|
str | int | float | bool | PointFloat | DimensionsFloat | DimensionsInt
|
Attribute value (str, int, float, bool, PointFloat, DimensionsFloat, or DimensionsInt). |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If value is not str, int, float, bool, PointFloat, DimensionsFloat, or DimensionsInt. |
ValueError
|
If an attribute with the same name exists with a different type. |
to_model()
Convert to a Pydantic CanvasTemplateModel instance.
Returns a pure-data Pydantic model suitable for serialization, API responses, and interoperability with web frameworks.
fdl.TemplateResult(fdl, _context_label, _canvas_id, _framing_decision_id)
dataclass
Result of applying a canvas template.
canvas
property
The new canvas created by the template apply.
context
property
The new context created by the template apply.
framing_decision
property
The new framing decision created by the template apply.