thorvg_python.paint¶
Submodules¶
Classes¶
Enumeration indicates the method used for blending paint. |
|
Enumeration indicating the method used in the masking of two objects - the target and the source. |
|
A data structure representing a three-dimensional matrix. |
|
A structure representing a graphical element. |
|
A data structure representing a point in two-dimensional space. |
|
Enumeration specifying the result from the APIs. |
|
Enumeration indicating the ThorVG object type value. |
|
Engine API |
|
Paint API |
Package Contents¶
- class thorvg_python.paint.BlendMethod¶
Bases:
enum.IntEnumEnumeration indicates the method used for blending paint. Please refer to the respective formulas for each method.
-
NORMAL =
0¶
-
MULTIPLY =
1¶
-
SCREEN =
2¶
-
OVERLAY =
3¶
-
DARKEN =
4¶
-
LIGHTEN =
5¶
-
COLORDODGE =
6¶
-
COLORBURN =
7¶
-
HARDLIGHT =
8¶
-
SOFTLIGHT =
9¶
-
DIFFERENCE =
10¶
-
EXCLUSION =
11¶
-
HUE =
12¶
-
SATURATION =
13¶
-
COLOR =
14¶
-
LUMINOSITY =
15¶
-
ADD =
16¶
-
COMPOSITION =
255¶
-
NORMAL =
- class thorvg_python.paint.MaskMethod¶
Bases:
enum.IntEnumEnumeration indicating the method used in the masking of two objects - the target and the source.
-
NONE =
0¶
-
ALPHA =
1¶
-
INVERSE_ALPHA =
2¶
-
LUMA =
3¶
-
INVERSE_LUMA =
4¶
-
ADD =
5¶
-
SUBTRACT =
6¶
-
INTERSECT =
7¶
-
DIFFERENCE =
8¶
-
LIGHTEN =
9¶
-
DARKEN =
10¶
-
NONE =
- class thorvg_python.paint.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.paint.PaintPointer¶
Bases:
ctypes.c_void_pA structure representing a graphical element.
Warning
The PaintPointer objects cannot be shared between Canvases.
Note
You should use
Paintclass instead.
- class thorvg_python.paint.PointStruct¶
Bases:
ctypes.StructureA data structure representing a point in two-dimensional space.
- _fields_¶
- class thorvg_python.paint.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.paint.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.paint.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.paint.Paint(engine: thorvg_python.engine.Engine, paint: thorvg_python.base.PaintPointer)¶
Paint API
A module for managing graphical elements. It enables duplication, transformation and composition.
This is base Paint class. Please instantiate with Shape, Picture, Scene or Text instead.
- engine¶
- thorvg_lib¶
- _paint¶
- _rel() thorvg_python.base.Result¶
Safely releases a Tv_Paint object.
This is the counterpart to the
new()API, and releases the given Paint object safely, handlingNoneand managing ownership properly.
- ref() int¶
Increment the reference count for the PaintPointer object.
This method increases the reference count of PaintPointer object, allowing shared ownership and control over its lifetime.
Warning
Please ensure that each call to Paint.ref() is paired with a corresponding call to Paint.unref() to prevent a dangling instance.
See also
Paint.unref()
See also
Paint.get_ref()
Added in version 1.0.
- deref(free: bool) int¶
Decrement the reference count for the PaintPointer object.
This method decreases the reference count of the PaintPointer object by 1. If the reference count reaches zero and the
freeflag is set to true, the instance is automatically deleted.- Parameters:¶
- free : bool¶
Flag indicating whether to delete the Paint instance when the reference count reaches zero.
- Returns:¶
The updated reference count after the decrement.
- Return type:¶
int
See also
Paint.ref()
See also
Paint.get_ref()
Added in version 1.0.
- get_ref() int¶
Retrieve the current reference count of the PaintPointer object.
This method provides the current reference count, allowing the user to check the shared ownership state of the PaintPointer object.
See also
Paint.ref()
See also
Paint.unref()
Added in version 1.0.
- set_visible(visible: bool) thorvg_python.base.Result¶
Sets the visibility of the Paint object.
This is useful for selectively excluding paint objects during rendering.
- Parameters:¶
- visible : bool¶
A boolean flag indicating visibility. The default is
true. -true: the object will be rendered by the engine. -false: the object will be excluded from the drawing process.
Note
An invisible object is not considered inactive—it may still participate in internal update processing if its properties are updated, but it will not be taken into account for the final drawing output. To completely deactivate a paint object, remove it from the canvas.
See also
Paint.get_visible()
See also
Canvas.remove()
Added in version 1.0.
- get_visible(visible: bool) thorvg_python.base.Result¶
Sets the visibility of the Paint object.
This is useful for selectively excluding paint objects during rendering.
- Parameters:¶
- visible : bool¶
A boolean flag indicating visibility. The default is
true. -true: the object will be rendered by the engine. -false: the object will be excluded from the drawing process.
Note
An invisible object is not considered inactive—it may still participate in internal update processing if its properties are updated, but it will not be taken into account for the final drawing output. To completely deactivate a paint object, remove it from the canvas.
See also
Paint.get_visible()
See also
Canvas.remove()
Added in version 1.0.
- scale(factor: float) thorvg_python.base.Result¶
Scales the given PaintPointer object by the given factor.
- Parameters:¶
- factor : float¶
The value of the scaling factor. The default value is 1.
- Returns:¶
Result.INVALID_ARGUMENT An invalid PaintPointer.
Result.INSUFFICIENT_CONDITION in case a custom transform is applied.
- Return type:¶
See also
Paint.set_transform()
- rotate(degree: float) thorvg_python.base.Result¶
Rotates the given PaintPointer by the given angle.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- Parameters:¶
- degree : float¶
The value of the rotation angle in degrees.
- Returns:¶
Result.INVALID_ARGUMENT An invalid PaintPointer.
Result.INSUFFICIENT_CONDITION in case a custom transform is applied.
- Return type:¶
See also
Paint.set_transform()
- translate(x: float, y: float) thorvg_python.base.Result¶
Moves the given PaintPointer in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- Parameters:¶
- Returns:¶
Result.INVALID_ARGUMENT An invalid PaintPointer.
Result.INSUFFICIENT_CONDITION in case a custom transform is applied.
- Return type:¶
See also
Paint.set_transform()
- set_transform(m: thorvg_python.base.Matrix) thorvg_python.base.Result¶
Transforms the given PaintPointer using the augmented transformation matrix.
The augmented matrix of the transformation is expected to be given.
- Parameters:¶
- m : thorvg_python.base.Matrix¶
The 3x3 augmented matrix.
- Returns:¶
Result.INVALID_ARGUMENT A
Noneis passed as the argument.- Return type:¶
- get_transform() tuple[thorvg_python.base.Result, thorvg_python.base.Matrix]¶
Gets the matrix of the affine transformation of the given PaintPointer object.
In case no transformation was applied, the identity matrix is returned.
- set_opacity(opacity: int) thorvg_python.base.Result¶
Sets the opacity of the given PaintPointer.
- Parameters:¶
- opacity : int¶
The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
- Returns:¶
Result.INVALID_ARGUMENT An invalid PaintPointer.
- Return type:¶
Note
Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible.
- get_opacity() tuple[thorvg_python.base.Result, int]¶
Gets the opacity of the given PaintPointer.
- duplicate() thorvg_python.base.PaintPointer | None¶
Duplicates the given PaintPointer object.
Creates a new object and sets its all properties as in the original object.
- Returns:¶
A copied PaintPointer object if succeed,
Noneotherwise.- Return type:¶
Optional[thorvg_python.base.PaintPointer]
- intersects(x: int, y: int, w: int, h: int) bool¶
Checks whether a given region intersects the filled area of the paint.
This function determines whether the specified rectangular region—defined by (x, y, w, h)— intersects the geometric fill region of the paint object.
This is useful for hit-testing purposes, such as detecting whether a user interaction (e.g., touch or click) occurs within a painted region.
The paint must be updated in a Canvas beforehand—typically after the Canvas has been drawn and synchronized.
Note
To test a single point, set the region size to w = 1, h = 1.
Note
For efficiency, an AABB (axis-aligned bounding box) test is performed internally before precise hit detection.
Note
This test does not take into account the results of blending or masking.
Note
This test does take into account the the hidden paints as well. See
Paint.set_visible().Added in version 1.0.
- get_aabb() tuple[thorvg_python.base.Result, float, float, float, float]¶
Retrieves the axis-aligned bounding box (AABB) of the paint object in canvas space.
Returns the bounding box of the paint as an axis-aligned bounding box (AABB), with all relevant transformations applied. The returned values
x,y,w,h, may have invalid if the operation fails. Thus, please check the retval.This bounding box can be used to determine the actual rendered area of the object on the canvas, for purposes such as hit-testing, culling, or layout calculations.
- Returns:¶
Result.INVALID_ARGUMENT An invalid
paint.Result.INSUFFICIENT_CONDITION If it failed to compute the bounding box (mostly due to invalid path information).
- Return type:¶
- Returns:¶
The x-coordinate of the upper-left corner of the bounding box.
- Return type:¶
float
- Returns:¶
The y-coordinate of the upper-left corner of the bounding box.
- Return type:¶
float
- Returns:¶
The width of the bounding box.
- Return type:¶
float
- Returns:¶
The height of the bounding box.
- Return type:¶
float
See also
Paint.get_obb()
See also
Canvas.update()
- get_obb() tuple[thorvg_python.base.Result, thorvg_python.base.PointStruct]¶
Retrieves the object-oriented bounding box (OBB) of the paint object in canvas space.
This function returns the bounding box of the paint, as an oriented bounding box (OBB) after transformations are applied. The returned values
pt4may have invalid if the operation fails. Thus, please check the retval.This bounding box can be used to obtain the transformed bounding region in canvas space by taking the geometry’s axis-aligned bounding box (AABB) in the object’s local coordinate space and applying the object’s transformations.
- Returns:¶
Result.INVALID_ARGUMENT
paintorpt4is invalid.Result.INSUFFICIENT_CONDITION If it failed to compute the bounding box (mostly due to invalid path information).
- Return type:¶
- Returns:¶
An array of four points representing the bounding box. The array size must be 4.
- Return type:¶
See also
Paint.get_aabb()
See also
Canvas.update()
Added in version 1.0.
- set_mask_method(target: Paint, method: thorvg_python.base.MaskMethod) thorvg_python.base.Result¶
Sets the masking target object and the masking method.
- Parameters:¶
- target : thorvg_python.paint.Paint¶
The target object of the masking.
- method : thorvg_python.base.MaskMethod¶
The method used to mask the source object with the target.
- Returns:¶
Result.INSUFFICIENT_CONDITION if the target has already belonged to another paint.
- Return type:¶
- get_mask_method(target: Paint) tuple[thorvg_python.base.Result, thorvg_python.base.MaskMethod]¶
Gets the masking target object and the masking method.
- set_clip(clipper: Paint) thorvg_python.base.Result¶
Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape’s paths.
- Parameters:¶
- clipper : thorvg_python.paint.Paint¶
The shape object as the clipper.
- Returns:¶
Result.INVALID_ARGUMENT In case a
Noneis passed as the argument.Result.NOT_SUPPORTED If the
clippertype is not Shape.
- Return type:¶
- get_clip() Paint | None¶
Get the clipper shape of the paint object.
This function returns the clipper that has been previously set to this paint object.
- Returns:¶
The shape object used as the clipper, or
Noneif no clipper is set.- Return type:¶
Optional[Paint]
See also
Paint.set_clip()
Added in version 1.0.
- get_parent() Paint | None¶
Retrieves the parent paint object.
This function returns a pointer to the parent object if the current paint belongs to one. Otherwise, it returns
None.See also
Scene.add()
See also
Canvas.add()
Added in version 1.0.
- get_type() tuple[thorvg_python.base.Result, thorvg_python.base.TvgType]¶
Gets the unique value of the paint instance indicating the instance type.
- set_blend_method(method: thorvg_python.base.BlendMethod) thorvg_python.base.Result¶
Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen
BlendMethod, which specifies how the colors or images are combined.- Parameters:¶
- method : thorvg_python.base.BlendMethod¶
The blending method to be set.
- Returns:¶
Result.INVALID_ARGUMENT In case a
Noneis passed as the argument.- Return type:¶
Added in version 0.15.