thorvg_python.gradient

Submodules

Classes

ColorStop

A data structure storing the information about the color and its relative position inside the gradient bounds.

GradientPointer

A structure representing a gradient fill of a PaintPointer object.

Matrix

A data structure representing a three-dimensional matrix.

Result

Enumeration specifying the result from the APIs.

StrokeFill

Enumeration specifying how to fill the area outside the gradient bounds.

TvgType

Enumeration indicating the ThorVG object type value.

Engine

Engine API

Gradient

Common Gradient API

Package Contents

class thorvg_python.gradient.ColorStop

Bases: ctypes.Structure

A data structure storing the information about the color and its relative position inside the gradient bounds.

_fields_
class thorvg_python.gradient.GradientPointer

Bases: ctypes.c_void_p

A structure representing a gradient fill of a PaintPointer object.

Note

You should use LinearGradient or RadialGradient class instead.

class thorvg_python.gradient.Matrix

Bases: ctypes.Structure

A data structure representing a three-dimensional matrix.

The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor.

The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively.

The elements e31 and e32 are set to 0, e33 is set to 1.

_fields_
class thorvg_python.gradient.Result

Bases: enum.IntEnum

Enumeration specifying the result from the APIs.

All ThorVG APIs could potentially return one of the values in the list. Please note that some APIs may additionally specify the reasons that trigger their return values.

SUCCESS = 0
INVALID_ARGUMENT = 1
INSUFFICIENT_CONDITION = 2
FAILED_ALLOCATION = 3
MEMORY_CORRUPTION = 4
NOT_SUPPORTED = 5
UNKNOWN = 255
classmethod from_param(obj: int) int
class thorvg_python.gradient.StrokeFill

Bases: enum.IntEnum

Enumeration specifying how to fill the area outside the gradient bounds.

PAD = 0
REFLECT = 1
REPEAT = 2
classmethod from_param(obj: int) int
class thorvg_python.gradient.TvgType

Bases: enum.IntEnum

Enumeration indicating the ThorVG object type value.

ThorVG’s drawing objects can return object type values, allowing you to identify the specific type of each object.

UNDEF = 0
SHAPE = 1
SCENE = 2
PICTURE = 3
TEXT = 4
LINEAR_GRAD = 10
RADIAL_GRAD = 11
classmethod from_param(obj: int) int
class thorvg_python.gradient.Engine(thorvg_lib_path: str | None = None, threads: int = 0)

Engine API

A module enabling initialization and termination of the TVG engines.

threads = 0
init_result
_load_lib(thorvg_lib_path: str | None = None) None
__del__() None
__enter__() Engine
__exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None) None
init(threads: int) thorvg_python.base.Result

Initializes TVG engines.

ThorVG requires an active runtime environment to operate. Internally, it utilizes a task scheduler to efficiently parallelize rendering operations. You can specify the number of worker threads using the threads parameter. During initialization, ThorVG will spawn the specified number of threads.

Parameters:
threads : int

The number of additional threads used to perform rendering. Zero indicates only the main thread is to be used.

Return type:

thorvg_python.base.Result

Note

The initializer uses internal reference counting to track multiple calls. The number of threads is fixed on the first call to Engine.init() and cannot be changed in subsequent calls.

See also

Engine.term()

term() thorvg_python.base.Result

Terminates TVG engines.

Cleans up resources and stops any internal threads initialized by Engine.init().

Returns:

Result.INSUFFICIENT_CONDITION Returned if there is nothing to terminate (e.g., Engine.init() was not called).

Return type:

thorvg_python.base.Result

See also

Engine.init()

version() tuple[thorvg_python.base.Result, int, int, int, str | None]

Retrieves the version of the TVG engine.

Returns:

Result.SUCCESS

Return type:

thorvg_python.base.Result

Returns:

A major version number.

Return type:

int

Returns:

A minor version number.

Return type:

int

Returns:

A micro version number.

Return type:

int

Returns:

The version of the engine in the format major.minor.micro, or a None in case of an internal error.

Return type:

Optional[str]

Added in version 0.15.

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

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

engine
thorvg_lib
_grad
set_color_stops(color_stop: collections.abc.Sequence[thorvg_python.base.ColorStop]) thorvg_python.base.Result

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

Parameters:
color_stop : Sequence[thorvg_python.base.ColorStop]

An array of ColorStop data structure.

Returns:

Result.INVALID_ARGUMENT An invalid GradientPointer.

Return type:

thorvg_python.base.Result

get_color_stops() tuple[thorvg_python.base.Result, collections.abc.Sequence[thorvg_python.base.ColorStop]]

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

The function does not allocate any memory.

Returns:

Result.INVALID_ARGUMENT A None passed as the argument.

Return type:

thorvg_python.base.Result

Returns:

An array of ColorStop data structure.

Return type:

Sequence[ColorStop]

set_spread(spread: thorvg_python.base.StrokeFill) thorvg_python.base.Result

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

Parameters:
spread : StrokeFill

The FillSpread value.

Returns:

Result.INVALID_ARGUMENT An invalid GradientPointer.

Return type:

thorvg_python.base.Result

get_spread() tuple[thorvg_python.base.Result, thorvg_python.base.StrokeFill]

Gets the FillSpread value of the gradient object.

Returns:

Result.INVALID_ARGUMENT A None passed as the argument.

Return type:

thorvg_python.base.Result

Returns:

The FillSpread value.

Return type:

StrokeFill

set_transform(m: thorvg_python.base.Matrix) thorvg_python.base.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:

Result.INVALID_ARGUMENT A None is passed as the argument.

Return type:

thorvg_python.base.Result

get_transform() tuple[thorvg_python.base.Result, thorvg_python.base.Matrix]

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

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

Returns:

Result.INVALID_ARGUMENT A None is passed as the argument.

Return type:

thorvg_python.base.Result

Returns:

The 3x3 augmented matrix.

Return type:

thorvg_python.base.Matrix

get_type() tuple[thorvg_python.base.Result, thorvg_python.base.TvgType]

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

Returns:

Result.INVALID_ARGUMENT In case a None is passed as the argument.

Return type:

thorvg_python.base.Result

Returns:

The unique type of the gradient instance type.

Return type:

thorvg_python.base.TvgType

Note

Experimental API

duplicate() Gradient | None

Duplicates the given GradientPointer object.

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

Returns:

A copied GradientPointer object if succeed, None otherwise.

Return type:

thorvg_python.base.GradientPointer

_del() thorvg_python.base.Result

Deletes the given gradient object.

Returns:

Result.INVALID_ARGUMENT An invalid GradientPointer.

Return type:

thorvg_python.base.Result