thorvg_python.gradient

class thorvg_python.gradient.Gradient(engine: Engine, grad: GradientStruct)

Bases: object

Common Gradient API

A module managing the gradient fill of objects.

The module enables to set and to get the gradient colors and their arrangement inside the gradient bounds, to specify the gradient bounds and the gradient behavior in case the area defined by the gradient bounds is smaller than the area to be filled.

This is base Gradient class. Please use LinearGradient or RadialGradient for creating

duplicate() Gradient | None

Duplicates the given GradientStruct object.

Creates a new object and sets its all properties as in the original object.

Returns:

A copied GradientStruct object if succeed, None otherwise.

Return type:

GradientStruct

get_color_stops() tuple[Result, Sequence[ColorStop]]

Gets the parameters of the colors of the gradient, their position and number

The function does not allocate any memory.

Returns:

INVALID_ARGUMENT A nullptr passed as the argument.

Return type:

Result

Returns:

An array of ColorStop data structure.

Return type:

Sequence[ColorStop]

get_identifier() tuple[Result, Identifier]

Deprecated since version 0.15.

See also

Gradient.get_type()

get_spread() tuple[Result, StrokeFill]

Gets the FillSpread value of the gradient object.

Returns:

INVALID_ARGUMENT A nullptr passed as the argument.

Return type:

Result

Returns:

The FillSpread value.

Return type:

StrokeFill

get_transform() tuple[Result, Matrix]

Gets the matrix of the affine transformation of the gradient object.

In case no transformation was applied, the identity matrix is set.

Returns:

INVALID_ARGUMENT A nullptr is passed as the argument.

Return type:

Result

Returns:

The 3x3 augmented matrix.

Return type:

Matrix

get_type() tuple[Result, TvgType]

Gets the unique value of the gradient instance indicating the instance type.

Returns:

INVALID_ARGUMENT In case a nullptr is passed as the argument.

Return type:

Result

Returns:

The unique type of the gradient instance type.

Return type:

TvgType

Note

Experimental API

set_color_stops(color_stop: Sequence[ColorStop]) Result

Sets the parameters of the colors of the gradient and their position.

Parameters:
color_stop : Sequence[ColorStop]

An array of ColorStop data structure.

Returns:

INVALID_ARGUMENT An invalid GradientStruct pointer.

Return type:

Result

set_spread(spread: StrokeFill) Result

Sets the StrokeFill value, which specifies how to fill the area outside the gradient bounds.

Parameters:
spread : StrokeFill

The FillSpread value.

Returns:

INVALID_ARGUMENT An invalid GradientStruct pointer.

Return type:

Result

set_transform(m: Matrix) Result

Sets the matrix of the affine transformation for the gradient object.

The augmented matrix of the transformation is expected to be given.

:param Matrix m The 3x3 augmented matrix.

Returns:

INVALID_ARGUMENT A nullptr is passed as the argument.

Return type:

Result