thorvg_python.gradient¶
Submodules¶
Classes¶
A data structure storing the information about the color and its relative position inside the gradient bounds. |
|
A structure representing a gradient fill of a PaintPointer object. |
|
A data structure representing a three-dimensional matrix. |
|
Enumeration specifying the result from the APIs. |
|
Enumeration specifying how to fill the area outside the gradient bounds. |
|
Enumeration indicating the ThorVG object type value. |
|
Engine API |
|
Common Gradient API |
Package Contents¶
- class thorvg_python.gradient.ColorStop¶
Bases:
ctypes.StructureA 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_pA structure representing a gradient fill of a PaintPointer object.
Note
You should use
LinearGradientorRadialGradientclass instead.
- class thorvg_python.gradient.Matrix¶
Bases:
ctypes.StructureA 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.IntEnumEnumeration 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¶
-
SUCCESS =
- class thorvg_python.gradient.StrokeFill¶
Bases:
enum.IntEnumEnumeration specifying how to fill the area outside the gradient bounds.
-
PAD =
0¶
-
REFLECT =
1¶
-
REPEAT =
2¶
-
PAD =
- class thorvg_python.gradient.TvgType¶
Bases:
enum.IntEnumEnumeration 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¶
-
UNDEF =
-
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¶
- __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
threadsparameter. 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:¶
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:¶
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:¶
- 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
Nonein case of an internal error.- Return type:¶
Optional[str]
Added in version 0.15.
-
threads =
- 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:¶
- 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.
- 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:¶
- get_spread() tuple[thorvg_python.base.Result, thorvg_python.base.StrokeFill]¶
Gets the FillSpread value of the gradient object.
- 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.
- 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.
- 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
Noneis passed as the argument.- Return type:¶
- Returns:¶
The unique type of the gradient instance type.
- Return type:¶
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.
- _del() thorvg_python.base.Result¶
Deletes the given gradient object.